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!