How to solve systems of non linear equation of dimensions 100 using ode45 matalb.

1 visualización (últimos 30 días)
how should i proceed if we want to implement its code?
  2 comentarios
Davide Masiello
Davide Masiello el 25 de Sept. de 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
RITIKA Jaiswal el 25 de Sept. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Davide Masiello
Davide Masiello el 25 de Sept. de 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 comentarios
RITIKA Jaiswal
RITIKA Jaiswal el 3 de Oct. de 2022
Editada: Torsten el 3 de Oct. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by