I'm a using matlab for the first time and my code has 2 errors which I don't know how to remove can you please take a look it is a 14 line code.

funtion sim_system tspan = 0:0.001:50; z0 = [1,0,sqrt(2),0]; [t,z]=ode45(@problem,tspan,z(0)); plot(t,z(:,1)); figure(); end
function zdot = problem(t,z) zdot = zeros(4,1); zdot(1)=z(2); zdot(2)=((2*sin(z(1))+(sin(z(1)-z(3))*z(4)*z(4))+(cos(z(1)-z(3))*sin(z(1)-z(3))*z(2)*z(2))-(cos(z(1)-z(3))*sin(z(3))))/((cos(z(1)-z(3))*cos(z(1)-z(3)))-2)); zdot(3)=z(4); zdot(4)=((-2*sin(z(1)-z(3))*z(2)*z(2))+(2*sin(z(3)))-(cos(z(1)-z(3))*sin(z(1)-z(3))*z(4)*z(4))+(2*cos(z(1)-z(3))*sin(z(1)))/((cos(z(1)-z(3))*cos(z(1)-z(3)))-2));

 채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 15일
편집: Mischa Kim 2014년 3월 15일
Ahmed, two things. In the ode45 call replace z(0) by z0 (you need all four initial conditions, but possibly just a typo)
[t,z] = ode45(@problem,tspan,z0)
And two, close the function problem with an end statement.

댓글 수: 1

There was one more error. I misspelled "function" in the first line. And thanks, your feedback really helped.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Linearization에 대해 자세히 알아보기

질문:

2014년 3월 15일

댓글:

2014년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by