Ode45 with functions problem.
6 ビュー (過去 30 日間)
古いコメントを表示
This is my function file "func1".
function fty = func1(t,y,c)
% t time interval.
% y vector with a, b, g
% c vector with constants s, q, w
fty = [s*(b-b*a+a-q*a^2); s^(-1)*(-b-a*b+g); w*(a-g)];
end
Commando file:
tspan = [0 10];
a = 30;
b = 1;
g = 30;
c = [a; b; g];
s = 1;
q = 1;
w = 0.1610;
y0 = [s; q; w];
[t,y] = ode45(@func1,tspan,y0,[],c);
plot(t,y)
I want to get a plot with a, b and g.
I can´t see what i´m doing wrong.
Thanks!
2 件のコメント
Jan
2011 年 8 月 5 日
Please use code formatting to improve the readability of your code. Use the "{} code" or read the "? MArkup" link.
Why do you assume, that you are doing something wrong? Do you get an error, if so, which message appears? Do the results differ from your expectations?
Arman Safdari
2011 年 8 月 6 日
plz, state your problem clearly, however according your codes obviously your function can not work with unknown variables. as well as, it is not depend on t and y so it means fty variable is constant for all processes and I guess it is not your aim because u can easily solve it analytically when dy is constant.
採用された回答
Jan
2011 年 8 月 5 日
I guess, that you get an error about unknown variables inside func1: a, b, g, q, s, w. func1 gets the input t, y and c - other variables are not known.
See this thread for using parameters inside ODE functions: Answers: Benefit of using anonymous function
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!