Solve an equation using eulers method and two different derivatives.
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!