Ode45 with functions problem.
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Jan
le 5 Août 2011
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
le 6 Août 2011
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.
Réponse acceptée
Jan
le 5 Août 2011
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!