DE (f) has wrong solution

조회 수: 1 (최근 30일)
Napsugár
Napsugár 2023년 5월 31일
답변: Steven Lord 2023년 5월 31일
[~] = f_2_3a()
function [t, x, A, C, dA, dC, f, g]=f_2_3a()
f = @(t, d) [(2 - d(2) / 5.2) * d(1); -(10 - d(1) / 1.25) * d(2); (0.7 - (d(1) + d(2)) / 8) * sin(d(3))];
d0 = [42.8; 19; 7];
t=[0 20] ; %a diffegyenlet megoldásának időlépései
x= ode45(f, t, d0); %a diffegyenlet változóinak értékei az adott időpillanatokban
b=15;
A= linspace(2, 300, 20); %a A értékek mátrixa, ahol kiértékeljük az iránymezőt
C= linspace(5, 200, 10); %a C értékek mátrixa, ahol kiértékeljük az iránymezőt
[A, C] = meshgrid(A, C);
dA= (2 - b/5.2)*A; %a vektormező pontjainak A irányú megváltozásai
dC= (0.7 - (A + b)/8).* sin(C); %a vektormező pontjainak C irányú megváltozásai
f=figure; %az iránymezős ábra
g=quiver(A, C, dA, dC, 'Color','r','LineWidth',1.5);
xlabel('a','FontWeight','bold','Color','g');
ylabel('c','FontWeight','bold','Color','b');
end
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 5월 31일
What is the correct solution then?
Are all the values used correct? Is the differential equation system you coded correct?

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2023년 5월 31일
Your code calls ode45 with an output argument but then doesn't use that output argument later in the code. In addition you're calling your main function with few enough output arguments that you could simply omit the ode45 call altogether and the only change it would make would be to speed up execution of your code.
In fact none of the lines of code inside your function before the ode45 call do anything useful in this context, as you can see from the fact that I removed them and the code still ran.
b=15;
A= linspace(2, 300, 20); %a A értékek mátrixa, ahol kiértékeljük az iránymezőt
C= linspace(5, 200, 10); %a C értékek mátrixa, ahol kiértékeljük az iránymezőt
[A, C] = meshgrid(A, C);
dA= (2 - b/5.2)*A; %a vektormező pontjainak A irányú megváltozásai
dC= (0.7 - (A + b)/8).* sin(C); %a vektormező pontjainak C irányú megváltozásai
f=figure; %az iránymezős ábra
g=quiver(A, C, dA, dC, 'Color','r','LineWidth',1.5);
xlabel('a','FontWeight','bold','Color','g');
ylabel('c','FontWeight','bold','Color','b');
If you want the quiver plot to show the solution to the system of ODEs, use it later in the code. MATLAB doesn't somehow automatically know you want to plot the solutions to the first and third ODEs that you solved with ode45. But if that's what you want (comparing the expressions in f and the expressions for dA and dC leads me to that conclusion) you may want to use deval to evaluate the solution at your selected points and use that in your visualization.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by