Thread Subject: problem in solving a PDE, please help

Subject: problem in solving a PDE, please help

From: Sunipa Som

Date: 24 Nov, 2009 09:40:24

Message: 1 of 3

Hi I have to solve the equation
dgdt((N*(i-1))+j,:) = (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1)+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*(i-1)+(j+1),:)-g(N*(i-1)+j,:))));

I am doing in this way
function dgdt=fg1(g,t)
N=100;
M=10;
m=2.61*9.109*10^(-31);
v=4.5*10^(3);
a= 0.5*1.602*10^(-13);
dr=0.2;
dgdt=zeros((N),size(g,2));
for i=2:N-1
  
    for j=2:N-1
       dgdt((N*(i-1))+j,:) = (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1)+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*(i-1)+(j+1),:)-g(N*(i-1)+j,:))));
    end
    
end
for j=1:N
dgdt(1,j)=0;
dgdt(N,j)=0;
end
for i= 2:N-1
    dgdt(i,1)=0;
    dgdt(i,N)=0;
end

-------------------------------------------------
>> N=200;
>> tspan=[0;100];
>> y0=(exp(-((1:N)/0.2).^2).*exp(-(((1:N)-50)/2).^2));
>> [t,g]=ode15s(@fg1,tspan,y0);??? Attempted to access g(202,:); index out of bounds because numel(g)=1.

Error in ==> fg1 at 12
       dgdt((N*(i-1))+j,:) =
       (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1)+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*(i-1)+(j+1),:)-g(N*(i-1)+j,:))));
       
Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ==> ode15s at 228
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
 
How can I solve it?
If ode15s is not working, which function will work or how I have to write the equation?

Sunipa

Subject: problem in solving a PDE, please help

From: Torsten Hennig

Date: 25 Nov, 2009 12:37:35

Message: 2 of 3

> Hi I have to solve the equation
> dgdt((N*(i-1))+j,:) =
> (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1
> )+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*
> (i-1)+(j+1),:)-g(N*(i-1)+j,:))));
>
> I am doing in this way
> function dgdt=fg1(g,t)
> N=100;
> M=10;
> m=2.61*9.109*10^(-31);
> v=4.5*10^(3);
> a= 0.5*1.602*10^(-13);
> dr=0.2;
> dgdt=zeros((N),size(g,2));
> for i=2:N-1
>
> for j=2:N-1
> dgdt((N*(i-1))+j,:) =
> +j,:) =
> (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1
> )+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*
> (i-1)+(j+1),:)-g(N*(i-1)+j,:))));
> end
>
> end
> for j=1:N
> dgdt(1,j)=0;
> dgdt(N,j)=0;
> end
> for i= 2:N-1
> dgdt(i,1)=0;
> dgdt(i,N)=0;
> end
>
> -------------------------------------------------
> >> N=200;
> >> tspan=[0;100];
> >>
> y0=(exp(-((1:N)/0.2).^2).*exp(-(((1:N)-50)/2).^2));
> >> [t,g]=ode15s(@fg1,tspan,y0);??? Attempted to
> access g(202,:); index out of bounds because
> numel(g)=1.
>
> Error in ==> fg1 at 12
> dgdt((N*(i-1))+j,:) =
>
>
>
>
>
>
> (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-
> 1)+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N
> *(i-1)+(j+1),:)-g(N*(i-1)+j,:))));
>
> Error in ==> odearguments at 110
> f0 = feval(ode,t0,y0,args{:}); % ODE15I sets
> args{1} to yp0.
>
> Error in ==> ode15s at 228
> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
> odeArgs, odeFcn, ...
>
> How can I solve it?
> If ode15s is not working, which function will work or
> how I have to write the equation?
>
> Sunipa

But you've already been told that MATLAB expects
dgdt to be a one-dimensional vector of the
same size as g.
Why do you still return a matrix for dgdt ?

Best wishes
Torsten.

Subject: problem in solving a PDE, please help

From: Sunipa Som

Date: 3 Dec, 2009 09:30:20

Message: 3 of 3

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <69357431.34848.1259152685561.JavaMail.root@gallium.mathforum.org>...
> > Hi I have to solve the equation
> > dgdt((N*(i-1))+j,:) =
> > (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1
> > )+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*
> > (i-1)+(j+1),:)-g(N*(i-1)+j,:))));
> >
> > I am doing in this way
> > function dgdt=fg1(g,t)
> > N=100;
> > M=10;
> > m=2.61*9.109*10^(-31);
> > v=4.5*10^(3);
> > a= 0.5*1.602*10^(-13);
> > dr=0.2;
> > dgdt=zeros((N),size(g,2));
> > for i=2:N-1
> >
> > for j=2:N-1
> > dgdt((N*(i-1))+j,:) =
> > +j,:) =
> > (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-1
> > )+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N*
> > (i-1)+(j+1),:)-g(N*(i-1)+j,:))));
> > end
> >
> > end
> > for j=1:N
> > dgdt(1,j)=0;
> > dgdt(N,j)=0;
> > end
> > for i= 2:N-1
> > dgdt(i,1)=0;
> > dgdt(i,N)=0;
> > end
> >
> > -------------------------------------------------
> > >> N=200;
> > >> tspan=[0;100];
> > >>
> > y0=(exp(-((1:N)/0.2).^2).*exp(-(((1:N)-50)/2).^2));
> > >> [t,g]=ode15s(@fg1,tspan,y0);??? Attempted to
> > access g(202,:); index out of bounds because
> > numel(g)=1.
> >
> > Error in ==> fg1 at 12
> > dgdt((N*(i-1))+j,:) =
> >
> >
> >
> >
> >
> >
> > (-(((2*v)/sqrt(M))*(sqrt(j)).*(g((N*(i))+j,:)-g(N*(i-
> > 1)+j,:)))+(((2*a*dr*sqrt(M))/(m*v))*(i.*sqrt(j)).*(g(N
> > *(i-1)+(j+1),:)-g(N*(i-1)+j,:))));
> >
> > Error in ==> odearguments at 110
> > f0 = feval(ode,t0,y0,args{:}); % ODE15I sets
> > args{1} to yp0.
> >
> > Error in ==> ode15s at 228
> > [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
> > odeArgs, odeFcn, ...
> >
> > How can I solve it?
> > If ode15s is not working, which function will work or
> > how I have to write the equation?
> >
> > Sunipa
>
> But you've already been told that MATLAB expects
> dgdt to be a one-dimensional vector of the
> same size as g.
> Why do you still return a matrix for dgdt ?
>
> Best wishes
> Torsten.

Hi,
We already wrote a matrix as a vector in the above equation.
Then we tried to apply it like example Brusselator system. Documentation ODE page 8-22.
Writing the hole equation by Forward Difference method, without using ode function we can solve it. But the result is not so appropriate.
Is there any way to solve that above equation by MATLAB and by using ode function?

With Regards
Sunipa Som

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com