How to solve systems of non linear equation of dimensions 100 using ode45 matalb.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示

how should i proceed if we want to implement its code?
2 件のコメント
It'd be best to post a first code attempt from your side, then we could try to help develop on that.
%odes solve with ode45 considering 10 states.
clear all;
clc;
close all;
syms g(x) u(t) x1(t) x2(t) x3(t) x4(t) x5(t) x6(t) x7(t) x8(t) x9(t) x10(t) Y;
g(x)=exp(40*x)+x-1;
A =[-g(x1)-g(x1-x2)+exp(-t); g(x1-x2)-g(x2-x3);g(x2-x3)-g(x3-x4);g(x3-x4)-g(x4-x5);g(x4-x5)-g(x5-x6);g(x5-x6)-g(x6-x7);g(x6-x7)-g(x7-x8);g(x7-x8)-g(x8-x9);g(x8-x9)-g(x9-x10);g(x9-x10)]
ode1 = diff(x1,t)==[-g(x1)-g(x1-x2)];
ode2= diff(x2,t)== g(x1-x2)-g(x2-x3);
ode3= diff(x3,t)== g(x2-x3)-g(x3-x4);
ode4= diff(x4,t)== g(x3-x4)-g(x4-x5);
ode5= diff(x5,t)== g(x4-x5)-g(x5-x6);
ode6= diff(x6,t)== g(x5-x6)-g(x6-x7);
ode7= diff(x7,t)== g(x6-x7)-g(x7-x8);
ode8= diff(x8,t)== g(x7-x8)-g(x8-x9);
ode9= diff(x9,t)== g(x8-x9)-g(x9-x10);
ode10= diff(x10,t)== g(x9-x10);
odes=[ode1;ode2;ode3;ode4;ode5;ode6;ode7;ode8;ode9;ode10]
%S = dsolve(odes)
[VF,Sbs] = odeToVectorField(odes)
%Sodsefcn = matlabFunction(VF)
Sodsefcn = matlabFunction(VF, 'Vars',{t,Y})
%y0=[0];
tspan=[0 7];
y0=[1 1 1 0 0 0 0 0 0 1];
ySol = ode45(@(t,Y)Sodsefcn(t,Y),tspan,y0);
tValues = linspace(tspan(1),tspan(2),100);
yValues = deval(ySol,tValues,1); %number 1 denotes first solution likewise you can mention 2 ,3 & 4 for the next three solutions
%Evaluate the first component of the solution at 1000 points in the interval [0 7].
plot(tValues,yValues)
title('With initial of y0 = [1 1 1 0 0 0 0 0 0 1]')
i tried like this but if we proceed like tis then we have to write a long code for N=100.
採用された回答
If I were you, I would proceed substantially differently.
Since you need to solve 100 equations, it is unthinkable to cde them one by one.
The key here is indexing.
For instance
clear,clc
tspan = [0,7];
x0 = zeros(1,1000); % substitute with correct initial conditions
dgn = ones(1,1000); dgn(251:750) = 1/2;
D = zeros(1000); D(logical(eye(1000))) = dgn;
options = odeset('Mass',D);
[t,X] = ode45(@odeFunc,tspan,x0,options);
function dxdt = odeFunc(t,x)
g = @(x) exp(40*x)+x-1;
dxdt(1,1) = -g(x(1))-g(x(1)-x(2))+exp(-t);
dxdt(2:length(x)-1,1) = g(x(1:end-2)-x(2:end-1))-g(x(2:end-1)-x(3:end));
dxdt(length(x),1) = g(x(end-1)-x(end));
end
12 件のコメント
Thankyou so much it really helped .
can you provide some refrences where i can learn more about indexing .It would be great help .
My pleasure. Please consider to accept the answer, it is customary to do so when it's found to be helpful.
yeah done
Hi, With reference to my earlier question I need to simulate my dynamical system over t = [0, 7] seconds and we need to have 2000 snapshots of
the dynamical system and the nonlinear function are collected with equidistant time steps. For this if i use tspan =linspace(0,7,2000) the X matrix i am getting of 2000*1000 and if i am using tspan =[0 7].
matrix of X i am getting is 1421*1000. Which one is correct ?
The ODE solver uses an adaptive time step. When you do not specify the number of time points, then it manages to integrate the equations in 1421 within the given tolerances.
When you specify that you want 2000 time steps, the solver just makes sure to report the solution at the time steps you asked for.
In summary, both solutions are correct.
Thanks for clearing my doubt.
The X matrix which we are getting here rows represent different time and column represents states right?
Correct.
thanks
RITIKA Jaiswal
2022 年 10 月 3 日
編集済み: Torsten
2022 年 10 月 3 日
I am trying to solve Sets of pdes in order to get discretize it.Using finite difference method such that the resulting ODEs approximate the essential dynamic information of the system.
I am not sure whether the code is correct. I have used first order forward difference and 2nd order centered difference.
i am unable to solv equation (2).Please guide.
clear all;
close all;
M=1000;
c=0.25;%lets dt/dr^2 =c
a=0.02;%lets dt/dr=a
r=0.01;
v=0.5;
for i =2:25
for j =2:25
p(i,j)=200;
end
end
dt=0.001;
dr=0.25;
for t=1:M
for i=2:25
for j =2:24
pp(i,j)=p(i,j)+(0.5*a)*(-v+(1/r))*(p(i,j+1)-p(i,j-1))+c*(p(i,j+1)-2*p(i,j)+p(i,j-1));
end
end
n=25;
pp(i,1:n)=500; %lets assume
pp(n,1:n)=500;
pp(1:n,1)=500;
pp(1:n,n)=500;
p=pp;
t=t;
end
figure
contourf(p,25,'linecolor','non')

this code is running i have also attached paper here for reference.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics and Optimization についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
