Ode45 with functions problem.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 5 de Ag. de 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
el 6 de Ag. de 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.
Respuesta aceptada
Jan
el 5 de Ag. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!