How to solve systems of non linear equation of dimensions 100 using ode45 matalb.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes

how should i proceed if we want to implement its code?
2 Comments
Davide Masiello
on 25 Sep 2022
It'd be best to post a first code attempt from your side, then we could try to help develop on that.
RITIKA Jaiswal
on 25 Sep 2022
%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.
Accepted Answer
Davide Masiello
on 25 Sep 2022
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 Comments
RITIKA Jaiswal
on 25 Sep 2022
Thankyou so much it really helped .
RITIKA Jaiswal
on 25 Sep 2022
can you provide some refrences where i can learn more about indexing .It would be great help .
Davide Masiello
on 25 Sep 2022
My pleasure. Please consider to accept the answer, it is customary to do so when it's found to be helpful.
RITIKA Jaiswal
on 25 Sep 2022
yeah done
RITIKA Jaiswal
on 26 Sep 2022
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 ?
Davide Masiello
on 26 Sep 2022
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.
RITIKA Jaiswal
on 27 Sep 2022
Thanks for clearing my doubt.
RITIKA Jaiswal
on 27 Sep 2022
The X matrix which we are getting here rows represent different time and column represents states right?
Torsten
on 27 Sep 2022
Correct.
RITIKA Jaiswal
on 27 Sep 2022
thanks
RITIKA Jaiswal
on 3 Oct 2022
Edited: Torsten
on 3 Oct 2022
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.
More Answers (0)
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)