Plot differential equations with respect to two variables in a 3d plane

6 ビュー (過去 30 日間)
UserCJ
UserCJ 2022 年 4 月 26 日
コメント済み: UserCJ 2022 年 4 月 28 日
I have a system of three differential equations and coded as follows.
I have a seperate function "first_term.m" to create the first part of the equation and another function "second_term.m" to create the second part. And then there is another function "add_RHS.m" to combine both these terms and pass it to ModelRHS(t,x,param).
Here's my add_RHS.m function that defines model equations.
if some condition > 0
dxdt(j) = dxdt(j) + first_term ;
end
if some condition < 0
dxdt(j) = dxdt(j) + second_term ;
end
Both these first and second terms consist of and . I need to plot vs vs in a 3D plane. Can someone plese suggest a way to do this? Simulation for this system of differential equations is given below.
editparams; %file that contains parameters
Tend = 100;
Nt = 100;
% Define RHS functions
RHS = @(t,x)RHS(t,x,param);
%Execution-----------------------------------------------------------------
x0 = [0.004, 0.05, 0.1]; %Initial condition
t = linspace(0,Tend,Nt); %TSPAN
[t, A] = ode45(RHS, t, x0);
  2 件のコメント
UserCJ
UserCJ 2022 年 4 月 26 日
No, I'm looking more likely for a surface plot.

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

採用された回答

Davide Masiello
Davide Masiello 2022 年 4 月 26 日
編集済み: Davide Masiello 2022 年 4 月 26 日
  24 件のコメント
Torsten
Torsten 2022 年 4 月 28 日
Looks better, but maybe you could scale dy3 by a factor of 10000.
UserCJ
UserCJ 2022 年 4 月 28 日
Thanks @Torsten. Yes, I did. It took so long to get in here!

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

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2022 年 4 月 27 日
編集済み: Bruno Luong 2022 年 4 月 27 日
Try this (adapt to your code):
%editparams; %file that contains parameters
Tend = 10;
Nt = 100;
% Define RHS functions
RHS = @(t,x) sin(t).*x.^2;
%Execution-----------------------------------------------------------------
x0 = rand; %Initial condition
t = linspace(0,Tend,Nt); %TSPAN
[t, x] = ode45(RHS, t, x0);
close all
tgrid = t;
Nx = 60;
xgrid = linspace(min(x),max(x),Nx);
[T,X] = meshgrid(tgrid,xgrid);
DXDT = RHS(T,X);
surf(tgrid,xgrid,DXDT);
hold on
dxdt = RHS(t,x);
plot3(t,x,dxdt,'r','Linewidth',3);
  6 件のコメント
Torsten
Torsten 2022 年 4 月 27 日
It won't work in your case since you solve for 3 unknown functions, not 1 as in Bruno's example code.
Bruno Luong
Bruno Luong 2022 年 4 月 27 日
編集済み: Bruno Luong 2022 年 4 月 27 日
In reply to your code
editparams
if some type of edge
if another type of edge
introduce parameters
addRHS
I would said modify my code to
Do something with your RHS to compute DXDT correctly

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

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by