Solve an equation using eulers method and two different derivatives.
显示 更早的评论
Hi! I need to write a matlab code to solve an equation using eulers method.
The given data is:
y'1= y1 + y2
y'2 = - y1 + y2
y1(0)= 1
y2(0)= 0
The step length is 0.1 and t goes to 1 (the interval is [0, 1])
If have written this code but there is a problem in the loop.
clear all
y1=1 %y1(0)=1
y2=0 %y2(0)=0
h=0.25
t_end=1
t=0
while(t<t_slut)
y1= y1 + h*(y1+y2)
y2= y2 + h*(-y1+y2)
t=t+h
end
Since y2 is using the already calculated value of y1 in the loop the answer is incorrect...
How to i structure my code to solve this problem?
Answers would be extremely appreciated.
Thank you in beforehand
Oskar
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!