필터 지우기
필터 지우기

ode45 two equations

조회 수: 1 (최근 30일)
Ibrahim Taha
Ibrahim Taha 2019년 12월 15일
댓글: Star Strider 2019년 12월 15일
Hi there!
I've got a question regarding ode45. There's this question where I've got a system of two equations, one describing y'=sin(xy) and the other x'=cos(x+y). I've got values for x(0) and y(0), which I decide. My issue is how I'm supposed to use ode45 to solve the equations. I'm supposed to draw a graph with the help of ode45. I have never seen a system of equations, where there is both x and x', y and y' on both sides of =.

채택된 답변

Star Strider
Star Strider 2019년 12월 15일
The ODE functions are defined with the derivative on the left-hand-side of the equal sign, and the expression on the right, so first define ‘x’ as ‘z(1)’ and ‘y’ as ‘z(2)’ (or any variable you want), then:
dzdt(1) = cos(z(1) + z(2)); % x'=cos(x+y)
dzdt(2) = cos(z(1) * z(2)); % y'=sin(xy)
That works for a function file, however this system can also be defined easily as an anonymous function:
dzdt = @(t,z) [cos(z(1) + z(2)); cos(z(1) * z(2))];
That will get you started.
I leave the rest to you.
If you have problems getting your complete code to run, post back here with the code you have written, and describing the problems.
  댓글 수: 2
Ibrahim Taha
Ibrahim Taha 2019년 12월 15일
Hi there!
Thank you so much for the help. The second method you suggested, calling an anonymous function instead of a function file was more efficient. I think I've figured it all out now. It seemed that I was confused about calling x=z(1) and y=z(2), but I understand it now.
Star Strider
Star Strider 2019년 12월 15일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by