solving ordinary differential equation
이전 댓글 표시
Hello , I am trying to solve an ode in matlab
but i'm getting syntax errors. pls help!!
my actual ODE is : m*d2xdt2 + a*(dxdt)^2 + k*x= Fcos(omega*t)
and i need a solution for x which is displacement for an object.
i am trying this way please correct me where i'm wrong
tspan=[0:1800];
x0=0;
[t,x]=ode45(@(t,x)EQ(tspan,x0,a,k,m,F,omega);
plot(t,x);
function sol= EQ(t,x)
a=1;
k=20;
m=0.5;
F=0.01;
omega=2*pi;
x=[(F/k)*cos(omega*t)- (m/k)*d2xdt2- (a/k)*(dxdt)^2]
sol=x ;
end
채택된 답변
추가 답변 (1개)
Walter Roberson
2021년 2월 19일
[t,x]=ode45(@(t,x)EQ(tspan,x0,a,k,m,F,omega);
That line tells us that ode45 is to call an anonymous function passing in two parameters, and that it is to throw away the parameters and call EQ passing in 7 variables whose values had to exist at the time the @ function handle was constructed
But ode45 must be passed at least 3 parameters not just one. The second passed to ode45 must be the time span and the third must be the initial conditions. So ode45 would fail.
If you were to pass the time span and initial conditions to ode45 then it would try to call the anonymous function, which would require recalling those 7 variables. However only tspan and x0 exist, and it would fail trying to find the other ones.
function sol= EQ(t,x)
If the variables did all exist then matlab would try to call EQ but would fail because EQ only expects two parameters.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
