i have error in this code while using ode45
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
%constants
A=2.6e-3;
B=90;
C=0.025;
D=5.0E-3;
E=0.3;
F=0.0041;
G=0.27;
H=83.7;
%Parameter Changes
A1=2.6e-2;
B1=80;
C1=0.025;
D1=6.0E-3;
E1=1;
F1=0.008;
G1=0.27;
H1=83.7;
%hold on
f=@(t,y) [-y(2) y(1) -A(y(1)-B); C*D*(y(3)-E) -C*y(2); -G*y(3) +F*max(0,y(1)-H)];
[t,xa]=ode45(f, [0 180], [250 :0 350]);
Index exceeds the number of array elements. Index must not exceed 1.
Error in solution (line 26)
f=@(t,y) [-y(2) y(1) -A(y(1)-B); C*D*(y(3)-E) -C*y(2); -G*y(3) +F*max(0,y(1)-H)];
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
disp(t,xa);
f=@(t,y) [-y(2) y(1) -A1(y(1)-B1); C1*D1*(y(3)-E1) -C1*y(2); -G1*y(3) +F1*max(0,y(1)-H1)];
[t,xb]=ode45(f, [0 180], [250 0 350]);
disp(t,xb);
figure(1)
plot(t,xa(:,1)+50,"LineWidth",2); ylabel("glucose(mm/dl)");
xlabel("time(min)");title('Glucose dynamics')
hold on
plot(t,xb(:,1),"LineWidth",2); ylabel("glucose(mm/dl)");
xlabel("time(min)");title('Glucose dynamics')
legend ('Orignal','Dexcom Curve')
hold off
%hold on
figure(2)
plot(t,xa(:,2)*33,"LineWidth",2); ylabel("Interstitial insulin(\uU/ml)");
xlabel("time(min)");title('Interstitial insulin dynamics')
hold on
plot(t,xb(:,2),"LineWidth",2); ylabel("Interstitial insulin(\uU/ml)");
xlabel("time(min)");title('Interstitial insulin dynamics')
legend ('Orignal','Dexcom Curve')
hold off
figure(3)
plot(t,xa(:,3)+5,"LineWidth",2); ylabel("Plasma insulin(\uU/ml)");
xlabel("time(min)");title('Plasma insulin dyanmics')
hold on
plot(t,xb(:,3),"LineWidth",2); ylabel("Plasma insulin(\uU/ml)");
xlabel("time(min)");title('Plasma insulin dyanmics')
legend ('Orignal','Dexcom Curve')
hold off
採用された回答
Walter Roberson
2022 年 5 月 23 日
[250 :0 350]
ans = 350
Your vector of initial conditions only has one entry.
Your line of code will not be interpreted as
[250, :0, 350]
and that would be a syntax error if it was.
Likewise it is not interpreted as [250 :0: 350] -- which would give you an empty vector.
The 250 :0 part is being intepreted as (250:0) -- the vector of values starting with 250, incrementing by 1, and ending with the first number that is greater than 0... and since 250 is greater than 0, that would be the empty array.
16 件のコメント
kainat rasheed
2022 年 5 月 23 日
@Walter Roberson so how should i actualy right. i am stuck in it
kainat rasheed
2022 年 5 月 23 日

kainat rasheed
2022 年 5 月 23 日
@Walter Roberson see these graphs i am writing this code for it. and these are my equations. i think i am doing wrong

When you call
[t,xa]=ode45(f, [0 180], [250 :0 350]);
the second [] is your initial conditions; with your code, you need three initial conditions.
I recommend that you do not use the : operator in defining your initial conditions. For example,
[t,xa]=ode45(f, [0 180], [250, 30, 350]);
but adjust that for your actual initial conditions. Do not compute them with expressions: just list them.
Since you chose names for the constants in your code that differ from those above it is impossible for us to correct your function line
f=@(t,y) [-y(2) y(1) -A(y(1)-B); C*D*(y(3)-E) -C*y(2); -G*y(3) +F*max(0,y(1)-H)];
kainat rasheed
2022 年 5 月 23 日
i know i think i type it wrong as [ 2 : 0 1]
but i am having error in ode45 function . it is saying t is unused here @Walter Roberson thats is my reall problem
kainat rasheed
2022 年 5 月 23 日
@Walter Roberson now tell me how should i actualy write this ode 45 line in this code
[~,xa]=ode45(f, [0 180], [2, 0, 1]);
f=@(t,y) [-y(2) y(1) -A(y(1)-B); C*D*(y(3)-E) -C*y(2); -G*y(3) +F*max(0,y(1)-H)];
your A is a constant not a function. You cannot index A at (y(1)-B)
MATLAB is completely lacking in implied multiplication. There are no cases in MATLAB in which P(Q) means that P is to be multiplied by Q.
kainat rasheed
2022 年 5 月 26 日
f=@(t,y) [-y(2)y(1)-A(y(1)-B);C*D*(y(3)-E)-C*y(2);-G*y(3)+F*max(0,y(1)-H)];
@Walter Roberson what if it is like this?
Let's play a game: search the two places where you forgot to include the "*" sign in the function definition.
kainat rasheed
2022 年 5 月 26 日
kainat rasheed
2022 年 5 月 26 日
@Torsten i think it worked. such small change helped me alot. thankyou so so much !
kainat rasheed
2022 年 5 月 26 日
@Torsten i enjoyed the game. it solved my problem. thankss
kainat rasheed
2022 年 5 月 27 日
You're welcome. I like people having humor.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
