How do I save a data file for numerically solution from PDE ?

Hello my name is Irving 

I'm a Maple primer. I want to solve an PDE numerically and then save the data to file.

  I used:
> restart;
> g:=0.2;
> PDE := diff(u(x,t),t,t) -diff(u(x,t),x,x) + g*diff(u(x,t),t) - 1/2*(u(x,t)-u(x,t)^3)=0 ;
> IBC := {u(x,0)= tanh(x),u(-15,t)= -1,u(15,t)= 1 ,D[2](u)(x,0)= -1/(cosh(x))^2};
> sol:= pdsolve(PDE,IBC,numeric,u(x,t));

 Then how can I print the formated data from pdsolve, in the following form: (three row)

time  x   solution 

I mean for one time fixed , vary x in a especific range , and put the solution that pdsolve give me.

Thanks you.

 

the value procedure does this

To get time, x, u values at a fixed time, e.g., t=1 use

u1:=sol:-value(u(x,t),t=1,output=listprocedure);

for x from -15 to 15 by 2 do rhs(u1[2]),x,rhs(u1[3])(x) end do;

gives:

                 1., -15, -0.99999999999995826

                 1., -13, -1.00000000159796176

                 1., -11, -1.00000001778633862

                  1., -9, -0.99999990540129812

                  1., -7, -1.00000347942147538

etc

 

How Can I save a data file for numerically solution from PDE ?

Hi  David

Thanks for your answer. Your approach is very good. but still have a litle limitation, is about time.

There is  a posibility to change time also  into  the procedure you posted it.  Can we implement  this into the problem?

So If we have the data in a file from PDE, this can provide a whole picture of the problem . Because we are able to analize the solution in deep.  The solution of this problem is important and general for any PDE to obtain a data file from the numerical  way that provide pdsolve.

 

Thanks

time and x

I not sure what you mean. You wanted "one time fixed , vary x in a especific range"? But if you want to vary x and t, just use the other form of value (see the help page for pdsolve,numeric)

ut:=sol:-value(u(x,t),output=listprocedure);
for tt from 0 to 1 by 0.2 do
   for xx from -5 to 5 by 2 do
      print(tt,xx,rhs(ut[3])(xx,tt));
   end do;
end do;

gives values of t,x and u, e.g., 

                 0, -5, -1.00011793431098361

                  0, -3, -0.995054753686730464

                  0, -1, -0.653755734133799948

                   0, 1, 0.653755734133799948

                   0, 3, 0.995054753686730464

                   0, 5, 1.00011793431098361

etc.

(You can also do a 3D plot to see the data:

sol:-plot3d(t=0..1,x=-15..15,axes=boxed);
)

 

 

  Irving Rondon In this

 

Irving Rondon

In this problem , we can solve numerically a PDE (in this case nonlinear),  then we can save it in a data file.
Thanks for the comment and improvement.

restart;
g:=0.2:
PDE := diff(u(x,t),t,t) -diff(u(x,t),x,x) + g*diff(u(x,t),t) - 1/2*(u(x,t)-u(x,t)^3)=0 ;
IBC := {u(x,0)= tanh(x),u(-15,t)= -1,u(15,t)= 1 ,D[2](u)(x,0)= -1/(cosh(x))^2}:
sol := pdsolve(PDE,IBC,'numeric',u(x,t)):
ut:=sol:-value(u(x,t),output=listprocedure):
file := "/home/irving/mydatos.dat":
 for tt from 0.2 to 10 by 0.2 do  
    for xx from -15 to 15 by 0.5 do
      fprintf(file,"%f %f %lf\n",tt,xx,rhs(ut[3])(xx,tt)):
   end do:
end do:
fclose(file):
 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}