Using Newton method for solving nonlinear system

9 ビュー (過去 30 日間)
Khai
Khai 2023 年 11 月 15 日
コメント済み: Khai 2023 年 11 月 15 日
Hi guys, please help me write a code program for my homework.
This is my lesson:
We have a lake and we want to determine its maximum teamperature, the temperature is T, and other affecting factors are the temperature of surrounding environment(Te), the amounts of UV rays(UV), the amounts of nutrients(N).
F1(T,Te,UV,N)=T−(Te​+0.5*UV−0.2*N)
F2(T,Te,UV,N)=Te-20
F3(T,Te,UV,N)=UV-5
F4(T,Te,UV,N)=N-2
T_zero=25, Te_zero=20, UV_zero=4, N_zero=1
Thanks to all. Please help me because i have tried lots of times but it just show a wrong result. And i don't have enough knowledge for solving this.
  2 件のコメント
Khai
Khai 2023 年 11 月 15 日
function main()
% Chọn điểm bắt đầu trong D
X0 = [25; 20; 4; 1];
% Áp dụng phương pháp Newton
X = newtons_method(X0);
% Hiển thị kết quả
disp('Kết quả:')
disp(['Nhiệt độ nước lớn nhất là: ', num2str(X(1))]);
end
function F = equations(X)
% Hệ phương trình phi tuyến
F = [X(1) - (X(2) + 0.5 * X(3) - 0.2 * X(4));
X(2) - 20;
X(3) - 5;
X(4) - 2];
end
function J = jacobian(X)
% Ma trận Jacobi
J = [1, -0.5, -0.1, 0.2;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1];
end
function X = newtons_method(X0)
% Phương pháp Newton
max_iterations = 100;
tolerance = 1e-6;
X = X0;
for i = 1:max_iterations
F = equations(X);
J = jacobian(X);
delta_X = -J \ F;
X = X + delta_X;
if norm(delta_X, inf) < tolerance
break;
end
end
end
Khai
Khai 2023 年 11 月 15 日
can someone help me to fix my code programe please

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by