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 次查看(过去 30 天)
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

采纳的回答

Alan Stevens
Alan Stevens 2022-11-24
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statics and Dynamics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by