Click here to Skip to main content
15,886,071 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI
hi

I am trying to solve two partial differential equation by converting it first into ODEs using finite difference and using ODE15s solver,but getting some error, pl help

What I have tried:

clc
clear all
m=50;  
delx=1/(m-1);
h_int=0.0005e7;
final_time=1e7; 
N_samples=(final_time/h_int)+1; 
t0=0;
tf=final_time;   
p_mat=zeros(m,N_samples);
p_mat(:,1)=2*10^5;
[t,p_mat] = ode15s(@GH,[t0 tf],p_mat(:,1));
T_mat=zeros(m,N_samples);
T_mat(:,1)=273;
[t,T_mat] = ode15s(@GH,[t0 tf],T_mat(:,1));

plot(t, p_mat);
xlabel('time'),ylabel('pressure');
plot(t, T_mat);
xlabel('time'),ylabel('Temp');
%%
function F_X= GH(t,p,T)

m=50;
delx=1/(m-1);
F_X=zeros(m,2);
dp_dt(i)=zeros(m,1);
dT_dt(i)=zeros(m,1);
% F_X = zeros(m,1);
% for i=1 and m
k=0.98*10^-12;
mu=0.001;
phi=0.4;
K1=k/((1-phi)*mu);
K2=1;
pg=2*10^5;
ph=30*10^5;
p(1)=pg;
p(m)=ph;
T(1)=273;
T(m)=283;
for i=2:m-1
dp_dt(i)=K1*((p(i+1)-2*p(i)+p(i-1))/(delx)^2);% K1 is k/(1-phi)*mu
dT_dt(i)=K2*((T(i+1)-2*T(i)+T(i-1))/(delx)^2);
F_X=[dp_dt(i) dT_dt(i)]';
end
end
Posted
Updated 3-Jan-22 7:24am
Comments
OriginalGriff 3-Jan-22 13:39pm    
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.
Use the "Improve question" widget to edit your question and provide better information.
0x01AA 3-Jan-22 13:39pm    
Quote: '... but getting some error ...'
Do you think about to tell us what the 'some' error is?
Member 15487602 3-Jan-22 13:51pm    
Unrecognized function or variable
'i'.

Error in PDEs>GH (line 27)
dp_dt(i)=zeros(m,1);

Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); %
ODE15I sets args{1} to yp0.

Error in ode15s (line 152)
odearguments(FcnHandlesUsed,
solver_name, ode, tspan, y0,
options, varargin);

Error in PDEs (line 12)
[t,p_mat] = ode15s(@GH,[t0
tf],p_mat(:,1));
0x01AA 3-Jan-22 17:49pm    
From where you copied that matlab code?
Sorry, I don't trust that story... you know about 'differential equation' and more 'partial differential equation' and you have problems to solve it numerical with matlab?

a.) Line 27: Yes there is no i
b.) Just about two lines below you have a commented for % for i=1 and m where the missing i apears

...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900