Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
solved ODE and solved PDE and adding a variable for both

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 9 Feb, 2010 12:53:03

Message: 1 of 28

Hi

I have solved ODE's system, geat thanks for Jan and Steve
and I have solved a PDE equation that gets parameters from the ODE's eq , thanks Steve
Each one has been seperately solved

Now i would add a variable to both (ODE and PDE), it is a addetional unknown for both which makes the PDE and ODE must solve together.

Any suggestion will be greatly appreciated

Regards

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 10 Feb, 2010 07:24:59

Message: 2 of 28

> Hi
>
> I have solved ODE's system, geat thanks for Jan and
> Steve
> and I have solved a PDE equation that gets parameters
> from the ODE's eq , thanks Steve
> Each one has been seperately solved
>
> Now i would add a variable to both (ODE and PDE), it
> is a addetional unknown for both which makes the PDE
> and ODE must solve together.
>
> Any suggestion will be greatly appreciated
>
> Regards
>
> Ib


Please precisely state the problem you try to solve.

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 10 Feb, 2010 11:34:04

Message: 3 of 28

Thanks Torsten for respond

I would make it simple so i have 2 ODE's (excpet T1,T2 all are known or computed and suppose To is constant )

dT1/dt = U1*A1*(T1-T2)- Us*As*(T1-To) +W+Q ---------------------------- (1)

dT2/dt = U2*A2*(T2-T1)- Ub*Ab*(T2-To) +M+Z ---------------------------- (2)

this system has been solved by ODE45 with help of Jan and Steve

The pde equation is

dT/dt=2*(d2T/dx2)+S (ie , Tt=2*Txx+S)
with BC
pl=ul
ql=0
pr=ur-To
qr=0

This pde has been solved as well.

So , ODE solved separately and PDE solve separately as well.

till haere there is no problem.

Now

I supposed To as a constant but now it is a variabl so it is a variable added to all equations ODE and PDE(through the BC)

Any further helps would be greatly appreciated as i need to solve it ASAP

Lovely Regards

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 10 Feb, 2010 12:13:04

Message: 4 of 28

> Thanks Torsten for respond
>
> I would make it simple so i have 2 ODE's (excpet
> T1,T2 all are known or computed and suppose To is
> constant )
>
> dT1/dt = U1*A1*(T1-T2)- Us*As*(T1-To) +W+Q
> ---------------------------- (1)
>
> dT2/dt = U2*A2*(T2-T1)- Ub*Ab*(T2-To) +M+Z
> ---------------------------- (2)
>
> this system has been solved by ODE45 with help of
> Jan and Steve
>
> The pde equation is
>
> dT/dt=2*(d2T/dx2)+S (ie , Tt=2*Txx+S)
> with BC
> pl=ul
> ql=0
> pr=ur-To
> qr=0
>
> This pde has been solved as well.
>
> So , ODE solved separately and PDE solve separately
> as well.
>
> till haere there is no problem.
>
> Now
>
> I supposed To as a constant but now it is a variabl
> so it is a variable added to all equations ODE and
> PDE(through the BC)
>
> Any further helps would be greatly appreciated as i
> need to solve it ASAP
>
> Lovely Regards
>
> Ib

How is T0 computed ?
I still do not see the need to solve PDE and ODEs
simultaneously.

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 10 Feb, 2010 13:47:04

Message: 5 of 28

Thanks for support

To is now unkown and need to be got . It is related to dT/dt in the PDE equation

Lovely thanks

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 11 Feb, 2010 16:09:04

Message: 6 of 28


Any idea or example about solving PDE and ODE simultaneously.

Is it possible?

Regards

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 12 Feb, 2010 17:03:47

Message: 7 of 28

>
> Any idea or example about solving PDE and ODE
> simultaneously.
>
> Is it possible?
>
> Regards
>
> Ib

The information you gave about the equations you
want to solve are not sufficient to give a precise
answer.

Of course it is sometimes possible to solve PDE and ODE
simultaneously: Use PDEPE and set the flux term to zero
for the ODE equation.
But if the boundary condition of the PDE depends
on the value of the ODE, then the use of PDEPE will
not be possible.

So more details about your special set of equations
and their coupling have to be provided.


Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 14 Feb, 2010 00:29:05

Message: 8 of 28

Hi Torsten

Thanks for the help and support

unfortunately, yes the boundary condition of PDE depends on the ODE's values

I am stuck in here, any alternative suggestions or solutions?>

Much of lovely regards

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 15 Feb, 2010 07:37:11

Message: 9 of 28

> Hi Torsten
>
> Thanks for the help and support
>
> unfortunately, yes the boundary condition of PDE
> depends on the ODE's values
>
> I am stuck in here, any alternative suggestions or
> solutions?>
>
> Much of lovely regards
>
> Ib

Then the only way to go is to disretize the PDE in space.
This results in a system of ODEs for the solution of
the PDE in each of the grid points.
Then add your ODE equations and solve the complete
system of ODEs with one of the solvers of the ODE suite
(e.g. ode15s).

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 15 Feb, 2010 11:57:02

Message: 10 of 28

Sir Torsten
Can you give me any simple example to follow it? from matlab help , any other websites or references? as i tried to search it but couldn't find any guide in this issue

kindest regards

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 15 Feb, 2010 12:55:57

Message: 11 of 28

> Sir Torsten
> Can you give me any simple example to follow it? from
> matlab help , any other websites or references? as i
> tried to search it but couldn't find any guide in
> this issue
>
> kindest regards
>
> Ib

Google for
'Method of lines'.

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 15 Feb, 2010 18:45:06

Message: 12 of 28

Thanks alot Torsten

after your help i have found some useful examples but as i am late enough and wouldn't waste more time and i am still biggener , so sorry for further questions .
Should i stop using pdepe and replace it by MOL , finite difference, etc?

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 16 Feb, 2010 07:32:29

Message: 13 of 28

> Thanks alot Torsten
>
> after your help i have found some useful examples but
> as i am late enough and wouldn't waste more time and
> i am still biggener , so sorry for further questions
> .
> Should i stop using pdepe and replace it by MOL ,
> finite difference, etc?

From what you wrote about your problem it is impossible
to couple PDE and ODE-part within pdepe.
pdepe itself is based on the MOL-approach ; so this
seems the most natural way to go.

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 16 Feb, 2010 13:55:53

Message: 14 of 28

> > Thanks alot Torsten
> >
> > after your help i have found some useful examples
> but
> > as i am late enough and wouldn't waste more time
> and
> > i am still biggener , so sorry for further
> questions
> > .
> > Should i stop using pdepe and replace it by MOL ,
> > finite difference, etc?
>
> From what you wrote about your problem it is
> impossible
> to couple PDE and ODE-part within pdepe.
> pdepe itself is based on the MOL-approach ; so this
> seems the most natural way to go.
>
> Best wishes
> Torsten.

Maybe you should start by setting up the PDE part
of the problem within the MOL-approach and compare the
results to those obtained by pdepe.
Adding the remaining 2 ODEs should then be a simple
task.

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 17 Feb, 2010 00:59:05

Message: 15 of 28

I don't know how to thanks you for this wonderful help

I found this example and i would develop it to solve my problem. it looks understandable.

http://200.13.98.241/~antonio/cursos/maths/notas/pdes/mol.pdf

but i couldn't understan me these lines (commands), what is this command (0,length,n,t); ?

% first-order derivative tx
%
tx = dss002 (0,length,n,t);
%
% second order derivative txx
%
txx = dss002 (0,length,n,tx);

if you have any comments can help me to save the time would be really great help

Lovely thanks

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 17 Feb, 2010 11:05:14

Message: 16 of 28

> I don't know how to thanks you for this wonderful
> help
>
> I found this example and i would develop it to solve
> my problem. it looks understandable.
>
> http://200.13.98.241/~antonio/cursos/maths/notas/pdes/
> mol.pdf
>
> but i couldn't understan me these lines (commands),
> what is this command (0,length,n,t); ?
>
> % first-order derivative tx
> %
> tx = dss002 (0,length,n,t);
> %
> % second order derivative txx
> %
> txx = dss002 (0,length,n,tx);
>
> if you have any comments can help me to save the time
> would be really great help
>
> Lovely thanks
>
> Ib

You have an array t of length n of function values -
one value in each of the n grid point in the intervall [0:length].
Now by the command
tx = dss002 (0,length,n,t);
you call a function dss002 with arguments xl=0,
xu=length, n and t to calculate an approximation
for the first-order spatial derivatives of t in the
grid points of the interval [0:length].
By the command
txx = dss002 (0,length,n,tx)
you call the same function to calculate an approximation
for the first-order spatial derivatives of tx in the
grid points of the interval [0:length], thus an
approximation for the second-order spatial derivatives
of t.

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 18 Feb, 2010 15:17:02

Message: 17 of 28

Your hand is very useful and blessed

I will try to do my best and will get back to you shortly

lovely thanks

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 2 Mar, 2010 11:48:04

Message: 18 of 28

Dear Sir Torsten

I have tried to solve them and i could got over some of the problems but the other problems need your kind help if you don't mind.


Solving PDE by MOL looks ok and ,as you told me, i have broken the PDE's down into ODE's and working fine

Now

I would insert my old ODE's with new ODE's (which came from PDEs) to solve them simultaneously but i hit two problems

First one is dimension problem as my new ODEs are

dT (i) = r2fdx*(-T(i-1)+T(i+1));

while my Old ODEs are like this

dT(1,1) =(Qsrs-Ut*As*(T(1)-T(n))-Ub*Ab*(T(1)-Tg))/(Cp*Ms);

How can i solve it?

I really appreciate your helps

Lovely Regards

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 2 Mar, 2010 12:14:59

Message: 19 of 28

> Dear Sir Torsten
>
> I have tried to solve them and i could got over some
> of the problems but the other problems need your kind
> help if you don't mind.
>
>
> Solving PDE by MOL looks ok and ,as you told me, i
> have broken the PDE's down into ODE's and working
> fine
>
> Now
>
> I would insert my old ODE's with new ODE's (which
> came from PDEs) to solve them simultaneously but i
> hit two problems
>
> First one is dimension problem as my new ODEs are
>
> dT (i) = r2fdx*(-T(i-1)+T(i+1));
>
> while my Old ODEs are like this
>
> dT(1,1)
> =(Qsrs-Ut*As*(T(1)-T(n))-Ub*Ab*(T(1)-Tg))/(Cp*Ms);
>
> How can i solve it?
>
> I really appreciate your helps
>
> Lovely Regards
>
> Ib

If you have stored the time derivatives of the PDE
variables in dy(1),...,dy(n), you could just store
the time derivatives of your ODE - variables in
dy(n+1),dy(n+2),... .
Is it that what you mean ?

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 2 Mar, 2010 13:21:04

Message: 20 of 28

Thanks Sir i will add them here

OLD ODE's

--------------------------- ODE Solver----------------------

fixed_omega_7
tspan=1:720;
T01=25;
T02=20;

for j=1:12
[t,T]= ode45(@fixed_omega_ode7,tspan,[T01 T02],[],Qsrs(j),Ut,As(j),Ab,Ub,Cp,Ms,Qur(j),Ap,Ta(j),Tg,he(j),hc(j),Pa(j),Ca,Patm,segma,Es,Tk(j));



Tnew(:,:,j)=T(:,:);
LT=squeeze(Tnew(:,1,:));
Tlw=LT(:);
UPT=squeeze(Tnew(:,2,:));
Tup=UPT(:);
T01=Tnew(length(tspan),1,j);

T02=Tnew(length(tspan),2,j);

end
figure(1);
plot(Tup)
title('Upper Zone Temperature');
figure(2);
plot(Tlw)
title('Lower Zone Temperature');
-------------------------------------------------------------EnD ODE SOLVER-------------------------------


-------------------------------------------- ODE ------------------------
function dT = fixed_omega_ode7(t,T,Qsrs,Ut,As,Ab,Ub,Cp,Ms,Qur,Ap,Ta,Tg,he,hc,Pa,Ca,Patm,segma,Es,Tk)


dT(1,1) =(Qsrs-Ut*As*(T(1)-T(2))-Ub*Ab*(T(1)-Tg))/(Cp*Ms);

dT(2,1)=(Qur+Ut*As*(T(1)-T(2))+Ub*Ab*(T(1)-Tg)-(hc*Ap*(T(2)-Ta))-(he*hc*Ap*((exp(18.403-(3885/(T(2)+230))))-Pa)/(1.6*Ca*Patm))-segma*Es*Ap*((T(1)+273.15)^4-(Tk^4)))/(Cp*Ms);
--------------------------------------------------------------END ODE----------------------------



------------------------------ some constants and variables is got from this file -----------

phi=29; %input ('Enter the latitude: '); % phi is the latitude which i a given value
gama=5; %input ('Enter the angel between the wall and south, it is negative toward East and positive toward west: ');
Lp=4; %input ('Enter the length of the solar pond: ');
Wp=2; %input ('Enter the width of the solar pond: ');
Xs=0.71; %input ('Enter the depth study of the storage zone im metre: ');
Xu=0.29; %input ('Enter the depth study of the upper zone im metre: ');
Hs=0.6; %input ('Enter the High of the solar pond wall from the surface to the storage zone: ');
IT=25; %input ('Enter the Initial Temperature: ');
segma=5.670e-8; % W/(m^2*k^4)
Au=Lp*Wp;
Anc=Lp*Wp;
Ap=Lp*Wp;
Ab=Lp*Wp;
Anc=0.4; % Non-Conv. zone Area
Tg=30;
Z2=0.4; %(gradient zone thickness)
h2=56.58; %W/m2.C, from Sodha
h3=48.28;
h4=78.92;
Kg=0.519; %W/m.C from Sodha
Kw=0.569;
Xg=30; %(assumption if there is ground water in 30 m deep)
h5=2; %(assumption if there is ground water)
rho=1088.6; % from Hull,in kg/m3 at 60 C
Cp=3570; % from Hull,in J/Kg.C at 60 C
Es=0.97; % from Hull
Ms=1; %(for 1 m3)
for i=1:12;
    N=[17 46 76 105 135 162 199 229 258 288 318 346];
delta(i)=23.45*sind(((284+N(i))/365)*360);

omega=2.25*(360/24);
theta(i)=acosd((cosd(phi)*cosd(delta(i))*cosd(omega))+(sind(phi)*sind(delta(i))));

nr=1.33;
r(i)=asind((sind(theta(i))/nr));

cc(i)=1/(cosd(r(i))+nr*cosd(theta(i)));
dc(i)=1/(cosd(theta(i))+nr*cosd(r(i)));

tau(i)=2*nr*cosd(theta(i))*cosd(r(i))*((cc(i))^2+(dc(i))^2);



psi(i)=sign(omega)*abs(acosd((cosd(theta(i))*sind(phi)-sind(delta(i)))/(sind(theta(i))*cosd(phi))));

if psi(i)==90
    psi(i)=89;
elseif psi(i)==-90
    psi(i)=-89;
end

alpha(i)=asind(cosd(theta(i)));
pa(i)=atand((tand(alpha(i))/cosd(psi(i)-gama)));

if pa(i)<=0.001 && pa(i)>-0.001
    pa(i)=0;
     As(i)=0;
     Ls(i)=0;
     Ws(i)=0;
end

Ls(i)=Lp-(Hs/tand(pa(i)));

if Ls(i)<0
    Ls(i)=0;
end

Ws(i)=Wp-(Hs/tand(pa(i)));

if Ws(i)<0
    Ws(i)=0;
end
end


for n=1:12

avH=[149.2510 171.3580 203.2890 250.9570 285.1440 323.3870 303.4550 293.7760 262.6400 203.2780 141.2500 128.8670];
Ta=[15.7538 16.8112 22.2290 27.6467 31.9329 33.5536 38.1823 38.6764 35.0458 31.2962 24.4172 16.7565];
V=[3.7 4.1 4.5 4.5 4.6 5.7 5.3 4.7 3.8 3.4 3.6 3.6]; % m/s from 'Potential wind power generation in the State of Kuwait'
% humidity in Kuwait from 'Potential fate of blistering chemical warfare agents on Kuwait's arid soil and related research needs'
gam=[65.079 58.0952 50.1587 42.8571 32.0635 21.5873 21.9048 26.3492 31.1111 40.3175 51.746 60];

As(n)=Ls(n)*Ws(n);

eta=[0.237 0.193 0.167 0.179];
mu=[0.32E-3 4.5E-3 0.03 0.35];

for k=1:4
Qsr(n,k)=eta(k)*exp(-mu(k)*Xs/cosd(r(n)));
sQsr(n)=sum(Qsr(n,1:k));
Qsru(n,k)=eta(k)*exp(-mu(k)*Xu/cosd(r(n)));
sQsru(n)=sum(Qsru(n,1:k));
% to calculate the radaition in the gradient zone we need to change depth
% as the this area is gradient, ie not lumped
Xgr=Xs;
Qnc(n,k)=eta(k)*exp(-mu(k)*Xgr/cosd(r(n)));
sQnc(n)=sum(Qnc(n,1:k));
end
Qsrs(n)=tau(n)*As(n)*avH(n)*sum(sQsr(n));

Quo(n)=tau(n)*Au*avH(n)*sum(sQsru(n));
Qui(n)=tau(n)*Ap*avH(n);
Qur(n)=Qui(n)-Quo(n);

Qncz(n)=tau(n)*Anc*avH(n)*sum(sQnc(n));

R3=1/h3;
Rc=Kw/Z2;
R2=1/h2;
Ut=1/(R3+Rc+R2);

R4=1/h4;
Rg=Kg/Xg;
R5=1/h5;
Ub=1/(R4+Rg+R5);


% heat convection transfer with atmospere
hc(n)=5.7+3.8*V(n);
%Quc(n)=hc(n)*Ap*(Tu(n)-Ta(n));
% heat exchange by radiation
Tk(n)=0.0552*((Ta(n)+273.15)^1.5); % Kelvin
%Quk(n)=segma*Es*Ap*((Tu(n)+273.15)^4-Tk^4);

% heat loss due to evaporation

he(n)=8.88+7.82*V(n);


Pa(n)=gam(n)*exp(18.403-(3885/(Ta(n)+230)));

Ca=1.009*1000/273.15; % at 60 C in J/Kg.C
Patm=1.01325e5; %(Pa)

%Pu(n)=Tu(n)*C1-C2;
%Pa(n)=gam(n)*(Ta(n)*C1-C2);
% function equation for solving ode

%Tu(n)=T(n,1);

%Pu(n)=exp(18.403-3885/(Tu+230));

%Que(n)=he(n)*hc(n)*Ap*(Pu(n)-Pa(n))/(1.6*Ca*Patm); % Patm is atmospheric Pressure in (Pa), Ca is air specific heat, see the turkish paper



%T(i)=Ta+(tau(i)*IT/U)-((tau(i)*IT/U)-(IT-Ta))*(exp(-U*3600*(dh(i)-sunrise(i))/(rho*Cp)));
end
------------------------------------------ EnD --------------------------------

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 2 Mar, 2010 13:27:06

Message: 21 of 28

My new ODEs which come from PDEs

SIMILAR TO THESE

%
% Main program for the numerical integration of
% the PDE modeling heat conduction in a solid slab.
%
global n length
%
% set the initial conditions
%
n = 51; % Number of grid points (including boundaries)
length = 1; % Length of the slab
dx = length/(n-1)
%
% Initial conditions definition
%
for i = 1:n,
x (i) = (i-1)*dx;
tic (i) = 100*sin(pi*x(i)/length);
end
tspan = linspace(0,1);
%
% Integration of the discretized PDE system

%
[time,temp] = ode15s('fcn',tspan,tic);
[lastp,nn] = size(time)
plot(temp(1,1:n)),hold,xlabel('x'),ylabel('T')
for i = 2:lastp,
plot(temp(i,1:n))
end
%-- End of the main.m file --




function fx = fcn (time,t)
global n length
%
% first-order derivative tx
%
tx = dss002 (0,length,n,t);
%
% second order derivative txx
%
txx = dss002 (0,length,n,tx);
%
% return the discretized value of the second order derivative
%
fx = txx';
%-- End of the fcn.m file --




function ux = dss002 (xl,xu,n,u)
%
% Function dss002 computes the first derivative, "ux", of a
% variable "u" over the spatial domain xl .le. x .le. xu from
% the classical three point, second order finite difference approximations.
%
% Inputs:
% -------
% xl = lower boundary value of x
% xu = upper boundary value of x
% n = number of grid points in the x domain
% including the boundary points
% u = one dimensional array containing the value of u at
% the n grid points for which the derivative is to be computed
%
% Outputs:
% -------
% ux = one dimensional array containing the numerical values of
% the derivatives of u at the n grid points
%
% Matlab version written by: Antonio Flores T./ April 2002
%
%
% Spatial increment
%
dx = (xu-xl)/(n-1);
r2fdx = 1/(2*dx);
nm1 = n-1;
%
% Equation (12)
%
ux (1) = % from Old ODEs eq dT(1,1)
%
% Equation (9)
%
for i = 2:nm1,
ux (i) = r2fdx*(-u(i-1)+u(i+1));
end
%
% Equation (13)
%
ux (n) = % from Old ODEs eq dT(2,1)

%-- End of the dss002.m file --


Thanks alot

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 3 Mar, 2010 21:48:04

Message: 22 of 28

Sir Torsten

I have tried to through the new ODEs which is represented by
 dT (i,1) = r2fdx*(-T(i-1)+T(i+1));

between the old ODEs

dT(1,1) =(Qsrs-Ut*As*(T(1)-T(2))-Ub*Ab*(T(1)-Tg))/(Cp*Ms);

dT(nv,1)=(Qur+Ut*As*(T(1)-T(nv))+Ub*Ab*(T(1)-Tg)-(hc*Ap*(T(nv)-Ta))-(he*hc*Ap*((exp(18.403-(3885/(T(nv)+230))))-Pa)/(1.6*Ca*Patm))-segma*Es*Ap*((T(1)+273.15)^4-(Tk^4)))/(Cp*Ms);


where the OLD ODEs are the boundary conditions

to be like this function
----------------------------------------------------------
function dT = fixed_omega_ode7(t,T,Qsrs,Ut,As,Ab,Ub,Cp,Ms,Qur,Ap,Ta,Tg,he,hc,Pa,Ca,Patm,segma,Es,Tk,Xs,Xu,nv,nm1,r2fdx)

for i = 2:nm1,
dT(1,1) =(Qsrs-Ut*As*(T(1)-T(2))-Ub*Ab*(T(1)-Tg))/(Cp*Ms);

 dT (i,1) = r2fdx*(-T(i-1)+T(i+1));

 dT(nv,1)=(Qur+Ut*As*(T(1)-T(nv))+Ub*Ab*(T(1)-Tg)-(hc*Ap*(T(nv)-Ta))-(he*hc*Ap*((exp(18.403-(3885/(T(nv)+230))))-Pa)/(1.6*Ca*Patm))-segma*Es*Ap*((T(1)+273.15)^4-(Tk^4)))/(Cp*Ms);

end

----------------------------------------------------------------

and solved by

for j=1:12
[t,T]= ode45(@fixed_omega_ode7,tspan,tic(j),[],Qsrs(j),Ut,As(j),Ab,Ub,Cp,Ms,Qur(j),Ap,Ta(j),Tg,he(j),hc(j),Pa(j),Ca,Patm,segma,Es,Tk(j),Xs,Xu,nv,nm1,r2fdx);




end

----------------------------------------


but i have gor this error

> In fixed_omega_7_solver at 6
Error in ==> fixed_omega_ode7 at 3
for i = 2:nm1,

??? Error using ==> feval
Output argument "dT" (and maybe others) not assigned during call to "C:\Users\caps
lock\Documents\MATLAB\mymol2\fixed_omega_ode7.m>fixed_omega_ode7".

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

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ==> fixed_omega_7_solver at 19
[t,T]= ode45(@fixed_omega_ode7,tspan,[T01
T02],[],Qsrs(j),Ut,As(j),Ab,Ub,Cp,Ms,Qur(j),Ap,Ta(j),Tg,he(j),hc(j),Pa(j),Ca,Patm,segma,Es,Tk(j),Xs,Xu,nv,nm1,r2fdx);

Subject: solved ODE and solved PDE and adding a variable for both

From: Ib Al

Date: 3 Mar, 2010 23:30:38

Message: 23 of 28

Sir Torsten

I think that i have found the error source.

Let me see what i can do.

I really really apreciate every moment you spent for me .

Thanks alot.

Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Nga Do

Date: 14 Jan, 2011 09:53:04

Message: 24 of 28

Hi lb and sir Torsten,

I met the same mistake as you. Could you please help me to figure out what is the error source? what should i do now?

The mistake is "
??? Error using ==> feval
Output argument "pl" (and maybe others) not assigned during call to
FDE1/pdex_emf1.m>pdex_emf1/pdex_abc"."

I am waiting for your reply.

Thank you very much.

QN



"IAN SAl" wrote in message <hmmreu$8km$1@fred.mathworks.com>...
> Sir Torsten
>
> I think that i have found the error source.
>
> Let me see what i can do.
>
> I really really apreciate every moment you spent for me .
>
> Thanks alot.
>
> Ib

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 14 Jan, 2011 10:22:43

Message: 25 of 28

> Hi lb and sir Torsten,
>
> I met the same mistake as you. Could you please help
> me to figure out what is the error source? what
> should i do now?
>
> The mistake is "
> ??? Error using ==> feval
> Output argument "pl" (and maybe others) not assigned
> during call to
> FDE1/pdex_emf1.m>pdex_emf1/pdex_abc"."
>
> I am waiting for your reply.
>
> Thank you very much.
>
> QN
>
>

According to the error message, you did not
assign a value to 'pl' in the subroutine
where you supply the boundary conditions of your
PDE ...

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Nga Do

Date: 17 Jan, 2011 15:25:07

Message: 26 of 28

Dear Torsten

Thank you very much for your reply. The errors were solved out. But i have another error here. Can you take a look and tell what kind of mistake i was in? Your help is very neccesary for me now.

This error is "
??? Attempted to access qL(1); index out of bounds because numel(qL)=0.

And the code is

global Dg Des Dred Dmred k1 k_1 k2 k3 k4 F x_tot alfa ...
     R T Eend Estart tend A cg_bulk cg0 ces0 cred0 cmred0 t time_step space_step ...
     cdl d_ml d_cl d_dl c_tot cm_tot Dmred_bulk Des_bulk Dg_bulk Dred_bulk


vic=0.655*1e-6;
Dg=4.02*1e-10;

Des=3*1e-2;
Dred=3*1e-2;
F=96485;
R=8.314;
Dmred=3*1e-8;
Dred_bulk =2*1e-4;
Dmred_bulk =3*1e-8;
Des_bulk =3*1e-3;
Dg_bulk=5*1e-5;

E_end=0.45;
E_ini=0.09;
alfa=0.5;
v=0.005;
T=273.15+37;
w=400;
cdl=50.8;
d_ml=1*5e-6;
d_cl=60e-6;
d_dl=1.61;
c_tot=.5;
cm_tot=1e-5;


k1=1.2e4;
k_1=36e5;
k2=1.7623;
k3=0.0104;
k4=0.0104;

tend=(Eend-Estart)/v;

A=0.8*10^-4;

cg_bulk = 1;

t=7200;
x_tot= d_ml+d_cl+d_dl;
space_step=100;
time_step=100;

cg0 = cg_bulk ;
ces0=0 ;
cred0=0 ;
cmred0=0 ;

pdex_emf1

function pdex_emf1
global u1 u2 x t time_step space_step u3 u4 x_tot c_tot cm_tot v alfa Estart...
              
m=0;

disp(x_tot);

size(x_tot)
size(space_step)
pause

x=linspace(0,x_tot,space_step);
size(x);

t=linspace(0,t,time_step);
size(t);
sol=pdepe(m,@pdex_apde,@pdex_aic,@pdex_abc,x,t);
pause
size(x);
size(t);
%______________________________________________________________________

u1=sol(:,:,1);
u2=sol(:,:,2);
u3=sol(:,:,3);
u4=sol(:,:,4);

function[c,f,s]=pdex_apde(x,t,u,DuDx)
    
global Dg Des Dred Dmred k1 k_1 k2 k3 k4 ceox cg ces cred cmox cmred ...
         F R T

cg=1*u1;
ces=1*u2;
cred=1*u3;
cmred=1*u4;

ceox=c_tot-u2-u3;
cmox=cm_tot-u4;

if x>=(2*x_tot/space_step) && x<=x_tot
c1=1;
c2=1;
c3=1;
c4=1;
c=[c1 ;c2; c3 ;c4];

f=[Dg*DuDx(1); Des*DuDx(2) ;Dred*DuDx(3); Dmred*DuDx(4)];
s1=0;
s2=0;
s3=0;
s4=0;
s=[s1; s2 ;s3 ;s4];
else
c1=1;
c2=1;
c3=1;
c4=1;
c=[c1 ;c2; c3 ;c4];
f=[Dg*DuDx(1); Des*DuDx(2) ;Dred*DuDx(3); Dmred*DuDx(4)];

s1=-k1*(c_tot-u2-u3)*u1 + k_1*u2;
s2=+k1*(c_tot-u2-u3)*u1 - k_1*u2-k2*u2;
s3=k2*u2-k3*u3*(cm_tot-u4);
s4=+k3*u3*(cm_tot-u4)-k4*u4*exp(alfa*F*(Estart+v*t)/(R*T));
s=[s1; s2 ;s3 ;s4];
end
length(s);

end

    function u0=pdex_aic(x)
        global cg0 ces0 cred0 cmred0
        u0=[cg0;ces0;cred0;cmred0];
    end
pause

    function [pl,ql,pr,qr]=pdex_abc(xl,ul,xr,ur,t)
        global k1 k3 k4 k_1 k2 Dg Des Dred Dmred ...
               F R T Dred_bulk Dmred_bulk Des_bulk Dg_bulk
  
          pl=[Dg; Des ;Dred; Dmred];
          s1=-k1*(c_tot-u2-u3)*u1 + k_1*u2;
          s2=k1*(c_tot-u2-u3)*u1 - k_1*u2-k2*u2;
          s3=k2*u2-k3*u3*(cm_tot-u4);
          s4=k3*u3*(cm_tot-u4)-k4*u4*exp(alfa*F*(Estart+v*t)/(R*T));
     
          ql=[s1; s2; s3; s4];
           
           pr=[0.86*Dg_bulk; 0.86*Des_bulk ;0.86*Dred_bulk; 0.86*Dmred_bulk];
           qr=[Dg; Des ;Dred; Dmred];
    end
end


I am waiting for your reply.

Thank you very much.

QN




Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <1685150784.26316.1295000593791.JavaMail.root@gallium.mathforum.org>...
> > Hi lb and sir Torsten,
> >
> > I met the same mistake as you. Could you please help
> > me to figure out what is the error source? what
> > should i do now?
> >
> > The mistake is "
> > ??? Error using ==> feval
> > Output argument "pl" (and maybe others) not assigned
> > during call to
> > FDE1/pdex_emf1.m>pdex_emf1/pdex_abc"."
> >
> > I am waiting for your reply.
> >
> > Thank you very much.
> >
> > QN
> >
> >
>
> According to the error message, you did not
> assign a value to 'pl' in the subroutine
> where you supply the boundary conditions of your
> PDE ...
>
> Best wishes
> Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: Torsten Hennig

Date: 18 Jan, 2011 07:48:43

Message: 27 of 28

> Dear Torsten
>
> Thank you very much for your reply. The errors were
> solved out. But i have another error here. Can you
> take a look and tell what kind of mistake i was in?
> Your help is very neccesary for me now.
>
> This error is "
> ??? Attempted to access qL(1); index out of bounds
> because numel(qL)=0.
>
> And the code is
>
> global Dg Des Dred Dmred k1 k_1 k2 k3 k4 F x_tot
> alfa ...
> R T Eend Estart tend A cg_bulk cg0 ces0 cred0
> cred0 cmred0 t time_step space_step ...
> cdl d_ml d_cl d_dl c_tot cm_tot Dmred_bulk
> _bulk Des_bulk Dg_bulk Dred_bulk
>
>
> vic=0.655*1e-6;
> Dg=4.02*1e-10;
>
> Des=3*1e-2;
> Dred=3*1e-2;
> F=96485;
> R=8.314;
> Dmred=3*1e-8;
> Dred_bulk =2*1e-4;
> Dmred_bulk =3*1e-8;
> Des_bulk =3*1e-3;
> Dg_bulk=5*1e-5;
>
> E_end=0.45;
> E_ini=0.09;
> alfa=0.5;
> v=0.005;
> T=273.15+37;
> w=400;
> cdl=50.8;
> d_ml=1*5e-6;
> d_cl=60e-6;
> d_dl=1.61;
> c_tot=.5;
> cm_tot=1e-5;
>
>
> k1=1.2e4;
> k_1=36e5;
> k2=1.7623;
> k3=0.0104;
> k4=0.0104;
>
> tend=(Eend-Estart)/v;
>
> A=0.8*10^-4;
>
> cg_bulk = 1;
>
> t=7200;
> x_tot= d_ml+d_cl+d_dl;
> space_step=100;
> time_step=100;
>
> cg0 = cg_bulk ;
> ces0=0 ;
> cred0=0 ;
> cmred0=0 ;
>
> pdex_emf1
>
> function pdex_emf1
> global u1 u2 x t time_step space_step u3 u4 x_tot
> c_tot cm_tot v alfa Estart...
>
> m=0;
>
> disp(x_tot);
>
> size(x_tot)
> size(space_step)
> pause
>
> x=linspace(0,x_tot,space_step);
> size(x);
>
> t=linspace(0,t,time_step);
> size(t);
> sol=pdepe(m,@pdex_apde,@pdex_aic,@pdex_abc,x,t);
> pause
> size(x);
> size(t);
> %_____________________________________________________
> _________________
>
> u1=sol(:,:,1);
> u2=sol(:,:,2);
> u3=sol(:,:,3);
> u4=sol(:,:,4);
>
> function[c,f,s]=pdex_apde(x,t,u,DuDx)
>
> global Dg Des Dred Dmred k1 k_1 k2 k3 k4 ceox cg
> ces cred cmox cmred ...
> F R T
>
> cg=1*u1;
> ces=1*u2;
> cred=1*u3;
> cmred=1*u4;
>
> ceox=c_tot-u2-u3;
> cmox=cm_tot-u4;
>
> if x>=(2*x_tot/space_step) && x<=x_tot
> c1=1;
> c2=1;
> c3=1;
> c4=1;
> c=[c1 ;c2; c3 ;c4];
>
> f=[Dg*DuDx(1); Des*DuDx(2) ;Dred*DuDx(3);
> Dmred*DuDx(4)];
> s1=0;
> s2=0;
> s3=0;
> s4=0;
> s=[s1; s2 ;s3 ;s4];
> else
> c1=1;
> c2=1;
> c3=1;
> c4=1;
> c=[c1 ;c2; c3 ;c4];
> f=[Dg*DuDx(1); Des*DuDx(2) ;Dred*DuDx(3);
> Dmred*DuDx(4)];
>
> s1=-k1*(c_tot-u2-u3)*u1 + k_1*u2;
> s2=+k1*(c_tot-u2-u3)*u1 - k_1*u2-k2*u2;
> s3=k2*u2-k3*u3*(cm_tot-u4);
> s4=+k3*u3*(cm_tot-u4)-k4*u4*exp(alfa*F*(Estart+v*t)/(R
> *T));
> s=[s1; s2 ;s3 ;s4];
> end
> length(s);
>
> end
>
> function u0=pdex_aic(x)
> global cg0 ces0 cred0 cmred0
> u0=[cg0;ces0;cred0;cmred0];
> end
> pause
>
> function [pl,ql,pr,qr]=pdex_abc(xl,ul,xr,ur,t)
> global k1 k3 k4 k_1 k2 Dg Des Dred Dmred
> ed Dmred ...
> F R T Dred_bulk Dmred_bulk Des_bulk
> d_bulk Des_bulk Dg_bulk
>
> pl=[Dg; Des ;Dred; Dmred];
> s1=-k1*(c_tot-u2-u3)*u1 + k_1*u2;
> s2=k1*(c_tot-u2-u3)*u1 - k_1*u2-k2*u2;
> s3=k2*u2-k3*u3*(cm_tot-u4);
>
>
>
>
>
>
>
>
>
> s4=k3*u3*(cm_tot-u4)-k4*u4*exp(alfa*F*(Estart+v*t)/(R
> *T));
>
> ql=[s1; s2; s3; s4];
>
> pr=[0.86*Dg_bulk; 0.86*Des_bulk
> 86*Des_bulk ;0.86*Dred_bulk; 0.86*Dmred_bulk];
> qr=[Dg; Des ;Dred; Dmred];
> end
> end
>
>
> I am waiting for your reply.
>
> Thank you very much.
>
> QN
>
>

Since you don't use a variable 'qL' above (only ql),
I don't know what the error message means.

In the code above, you set the boundary condition for
u1 at the left boundary point e.g. to
Dg + Dg*du1/dx*(-k1*(c_tot-u2-u3)*u1+k1*u2) = 0
Is that really what you want ?

Best wishes
Torsten.

Subject: solved ODE and solved PDE and adding a variable for both

From: mlohano@gmail.com

Date: 16 Dec, 2013 21:29:16

Message: 28 of 28

On Tuesday, 9 February 2010 17:53:03 UTC+5, Ib Al wrote:
> Hi
>
> I have solved ODE's system, geat thanks for Jan and Steve
> and I have solved a PDE equation that gets parameters from the ODE's eq , thanks Steve
> Each one has been seperately solved
>
> Now i would add a variable to both (ODE and PDE), it is a addetional unknown for both which makes the PDE and ODE must solve together.
>
> Any suggestion will be greatly appreciated
>
> Regards
>
> Ib

send me ur full code if u can

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us