フィルターのクリア

How to solve a system of nonlinear differential equation that follows some pattern

2 ビュー (過去 30 日間)
MADHAN
MADHAN 2024 年 6 月 7 日
回答済み: Sam Chak 2024 年 6 月 7 日
I have a system of nonlinear differential equation that follows some patter, for example . I could solve for some small n. I want to solve it for . Is there any way to do that or we can tonly type manually. Is it possible to use loops in function environment to solve such cases? Thank you!

回答 (2 件)

Torsten
Torsten 2024 年 6 月 7 日
編集済み: Torsten 2024 年 6 月 7 日
function dy = fun(t,y)
dy = y.*[y(2:end);y(1)]
end
or a function handle
fun = @(t,y) y.*[y(2:end);y(1)]

Sam Chak
Sam Chak 2024 年 6 月 7 日
The looping approach is given as follows:
%% for-loop approach
function dx = ode1(t, x, n)
dx = zeros(n, 1);
for i = 1:n-1
dx(i) = x(i)*x(i+1);
end
dx(n) = x(n)*x(1);
end
%% direct equations (for comparison)
function dx = ode2(t, x, n)
dx = zeros(n, 1);
dx(1) = x(1)*x(2);
dx(2) = x(2)*x(3);
dx(3) = x(3)*x(4);
dx(4) = x(4)*x(1);
end
[t, x] = ode45(@(t, x) ode1(t, x, 4), [0 0.2], [1; 2; 3; 4]);
plot(t, x), grid on, xlabel('t')

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by