I'm trying to solve a system of differential equations using Euler's method, but I don't know what the problem is with my code. If you can correct me the problem

2 Ansichten (letzte 30 Tage)
clear
clc
clf
a= 0;
b= 2;
delta_x =0.5;
y1 (1) = 4;
y2 (1) = 6;
n= (b-a)/delta_x + 1 ;
x (1) = 0;
funcl =@(yl) - 0.5*yl ;
func2=@(y1, y2) 4 - 0.3* y2 - 0.1* yl ;
for i= 1:n-1
x(i+1)= i* delta_x;
y1 (i+1)= y1 (i) + delta_x * feval (funcl, yl (i));
y2 (i+1)= y2 (i)+ delta_x * feval (func2, y1 (i), y2 (i));
end
x
y1
y2
plot (x, y1, x, y2)
title('Plot of x va yi & y2 - Explicit Euler')
grid on

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 24 Nov. 2022
Don't confuse the number 1 with lower case l
a= 0;
b= 2;
delta_x =0.5;
y1(1) = 4;
y2(1) = 6;
n= (b-a)/delta_x + 1 ;
x(1) = 0;
func1 =@(yl) - 0.5*yl ;
func2=@(y1, y2) 4 - 0.3* y2 - 0.1* y1 ;
for i= 1:n-1
x(i+1)= i* delta_x;
y1(i+1)= y1(i) + delta_x * feval(func1,y1(i));
y2(i+1)= y2(i)+ delta_x * feval(func2, y1(i),y2(i));
end
plot (x, y1, x, y2)
title('Plot of x va yi & y2 - Explicit Euler')
grid on
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Statics and Dynamics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by