Ode45 with functions problem.

조회 수: 6 (최근 30일)
Martin
Martin 2011년 8월 5일
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
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
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
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개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by