Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10282 > unrolled thread

solving DE numerically....

Started byraj kumar <rajesh7796gm@gmail.com>
First post2012-05-31 06:51 +0000
Last post2012-06-01 09:17 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  solving  DE numerically.... raj kumar <rajesh7796gm@gmail.com> - 2012-05-31 06:51 +0000
    Re: solving  DE numerically.... danl@wolfram.com - 2012-06-01 09:17 +0000
    Re: solving  DE numerically.... "Kevin J. McCann" <kjm@KevinMcCann.com> - 2012-06-01 09:17 +0000

#10282 — solving DE numerically....

Fromraj kumar <rajesh7796gm@gmail.com>
Date2012-05-31 06:51 +0000
Subjectsolving DE numerically....
Message-ID<jq74dd$qj1$1@smc.vnet.net>
hi all,
greetings from sunny malaysia!
this pertains to solving a  DE numerically at 5 differnt points.Should be straigth forward. But i get different results when i try to insert one parameter "by hand".have i overlooked something?

any feed-back will be most appreciated  

Please consider the following:

In[137]:= pw3 = Piecewise[{{V0, x < a}, {V0, x == a}}, 0];
k = Sqrt[10 - pw3];
V0 = -1;
a = 2;
Table[{x, k}, {x, 1, 5}]
(*Plot[Piecewise[{{V0, x<a}, {V0,x==a}},0],{x,0,5}]*)


Out[141]= {{1, Sqrt[11]}, {2, Sqrt[11]}, {3, Sqrt[10]}, {4, Sqrt[
  10]}, {5, Sqrt[10]}}

Solve the following DE numerically for y1[
  1.0], y1[2.0], y1[3], y1[4], y1[5]

In[148]:= 
s33 = NDSolve[{(y1^\[Prime]\[Prime])[x] + Sqrt[k] y1[x] == 0, 
    y1[0.1] == 0, Derivative[1][y1][0.1] == 1/10^6}, y1, {x, 1, 10}];


We obtain  

In[149]:= {y1[1.0], y1[2.0], y1[3], y1[4], y1[5]} /. s33

Out[149]= {{6.9408*10^-7, 
  4.08303*10^-7, -5.09458*10^-7, -6.64851*10^-7, 1.70684*10^-7}}

now check the output above for the values  x = 
 1 to x = 5. For x = 1, 2, 
we insert k = 
 Sqrt[11] by hand in the same DE above and work out the values for \
the same points again.  We get 

In[144]:= 
s11 = NDSolve[{(y11^\[Prime]\[Prime])[x] + Sqrt[ 11] y11[x] == 0, 
    y11[0.1] == 0, Derivative[1][y11][0.1] == 1/10^6}, 
   y11, {x, 1, 10}];

In[145]:= {y11[1.0], y11[2.0]} /. s11

Out[145]= {{5.47931*10^-7, -1.68202*10^-7}}

Out[105]= {{5.47931*10^-7, -1.68202*10^-7}}

For x = 3, 4, 5, k = Sqrt[10]. We get

In[146]:= 
s11 := NDSolve[{(y11^\[Prime]\[Prime])[x] + Sqrt[10] y11[x] == 0, 
    y11[0.1] == 0, Derivative[1][y11][0.1] == 1/10^6}, 
   y11, {x, 1, 10}];



In[147]:= {y11[3], y11[4], y11[5]} /. s11

Out[147]= {{-5.30318*10^-7, 3.34051*10^-7, 4.16315*10^-7}}

Qn : Should  the values for  y11[1-5] be any different from that calculated earlier ie  y1[1-5]?

[toc] | [next] | [standalone]


#10295

Fromdanl@wolfram.com
Date2012-06-01 09:17 +0000
Message-ID<jqa1bf$bgr$1@smc.vnet.net>
In reply to#10282
On Thursday, May 31, 2012 1:51:25 AM UTC-5, raj kumar wrote:
> hi all,
> greetings from sunny malaysia!
> this pertains to solving a  DE numerically at 5 differnt points.Should be straigth forward. But i get different results when i try to insert one parameter "by hand".have i overlooked something?
> 
> any feed-back will be most appreciated  
> 
> Please consider the following:
> 
> In[137]:= pw3 = Piecewise[{{V0, x < a}, {V0, x == a}}, 0];
> k = Sqrt[10 - pw3];
> V0 = -1;
> a = 2;
> Table[{x, k}, {x, 1, 5}]
> (*Plot[Piecewise[{{V0, x<a}, {V0,x==a}},0],{x,0,5}]*)
> 
> 
> Out[141]= {{1, Sqrt[11]}, {2, Sqrt[11]}, {3, Sqrt[10]}, {4, Sqrt[
>   10]}, {5, Sqrt[10]}}
> 
> Solve the following DE numerically for y1[
>   1.0], y1[2.0], y1[3], y1[4], y1[5]
> 
> In[148]:= 
> s33 = NDSolve[{(y1^\[Prime]\[Prime])[x] + Sqrt[k] y1[x] == 0, 
>     y1[0.1] == 0, Derivative[1][y1][0.1] == 1/10^6}, y1, {x, 1, 10}];
> 
> 
> We obtain  
> 
> In[149]:= {y1[1.0], y1[2.0], y1[3], y1[4], y1[5]} /. s33
> 
> Out[149]= {{6.9408*10^-7, 
>   4.08303*10^-7, -5.09458*10^-7, -6.64851*10^-7, 1.70684*10^-7}}
> 
> now check the output above for the values  x = 
>  1 to x = 5. For x = 1, 2, 
> we insert k = 
>  Sqrt[11] by hand in the same DE above and work out the values for \
> the same points again.  We get 
> 
> In[144]:= 
> s11 = NDSolve[{(y11^\[Prime]\[Prime])[x] + Sqrt[ 11] y11[x] == 0, 
>     y11[0.1] == 0, Derivative[1][y11][0.1] == 1/10^6}, 
>    y11, {x, 1, 10}];
> 
> In[145]:= {y11[1.0], y11[2.0]} /. s11
> 
> Out[145]= {{5.47931*10^-7, -1.68202*10^-7}}
> 
> Out[105]= {{5.47931*10^-7, -1.68202*10^-7}}
> 
> For x = 3, 4, 5, k = Sqrt[10]. We get
> 
> In[146]:= 
> s11 := NDSolve[{(y11^\[Prime]\[Prime])[x] + Sqrt[10] y11[x] == 0, 
>     y11[0.1] == 0, Derivative[1][y11][0.1] == 1/10^6}, 
>    y11, {x, 1, 10}];
> 
> 
> 
> In[147]:= {y11[3], y11[4], y11[5]} /. s11
> 
> Out[147]= {{-5.30318*10^-7, 3.34051*10^-7, 4.16315*10^-7}}
> 
> Qn : Should  the values for  y11[1-5] be any different from that calculated earlier ie  y1[1-5]?

As you note, k is sqrt(11) for x<2. You are using sqrt(k) in your DE, not k, so you'd want (11)^(1/4) rather than sqrt(11) in the second DE.

Daniel Lichtblau
Wolfram Research

[toc] | [prev] | [next] | [standalone]


#10305

From"Kevin J. McCann" <kjm@KevinMcCann.com>
Date2012-06-01 09:17 +0000
Message-ID<jqa1ah$bgd$1@smc.vnet.net>
In reply to#10282
Greetings from a rather steamy Washington, DC.

I think your problem is that k is a function of x not a fixed parameter 
in the DE. Here is my take on your problem. I made both pw3 and k 
explicit functions of x. Drop this into a notebook, put the cursor in 
the cell and type ctrl-shift-n to make it look nice.

Cheers,

Kevin

Clear[pw3, x, k]
(* note the set delayed (:=) in the next two *)
pw3[x_] := Piecewise[{{V0, x < a}, {V0, x == a}}, 0];
k[x_] := Sqrt[10 - pw3[x]];
V0 = -1;
a = 2;
Table[{x, k[x]}, {x, 1, 5}]
Plot[pw3[x], {x, 0, 5}]
s33 = NDSolve[{(y1^\[Prime]\[Prime])[x] + Sqrt[k[x]] y1[x] == 0,
    y1[0.1] == 0, Derivative[1][y1][0.1] == 10^-6}, y1, {x, 0.1, 10}]
Y1 = y1 /. s33[[1]]
(*Check the IC *)
{Y1[0.1], Y1'[0.1]}
Table[{x, Y1[x]}, {x, 1, 5, 1}]
Plot[Y1[x], {x, 0.1, 10}]
(* Check that the de is zero (almost) *)
Plot[(Y1^\[Prime]\[Prime])[x] + Sqrt[k[x]] Y1[x], {x, 0.1, 10}]

On 5/31/2012 2:51 AM, raj kumar wrote:
> hi all,
> greetings from sunny malaysia!
> this pertains to solving a  DE numerically at 5 differnt points.Should be straigth forward. But i get different results when i try to insert one parameter "by hand".have i overlooked something?
>
> any feed-back will be most appreciated
>
> Please consider the following:
>
> In[137]:= pw3 = Piecewise[{{V0, x<  a}, {V0, x == a}}, 0];
> k = Sqrt[10 - pw3];
> V0 = -1;
> a = 2;
> Table[{x, k}, {x, 1, 5}]
> (*Plot[Piecewise[{{V0, x<a}, {V0,x==a}},0],{x,0,5}]*)
>
>
> Out[141]= {{1, Sqrt[11]}, {2, Sqrt[11]}, {3, Sqrt[10]}, {4, Sqrt[
>    10]}, {5, Sqrt[10]}}
>
> Solve the following DE numerically for y1[
>    1.0], y1[2.0], y1[3], y1[4], y1[5]
>
> In[148]:=
> s33 = NDSolve[{(y1^\[Prime]\[Prime])[x] + Sqrt[k] y1[x] == 0,
>      y1[0.1] == 0, Derivative[1][y1][0.1] == 1/10^6}, y1, {x, 1, 10}];
>
>
> We obtain
>
> In[149]:= {y1[1.0], y1[2.0], y1[3], y1[4], y1[5]} /. s33
>
> Out[149]= {{6.9408*10^-7,
>    4.08303*10^-7, -5.09458*10^-7, -6.64851*10^-7, 1.70684*10^-7}}
>
> now check the output above for the values  x =
>   1 to x = 5. For x = 1, 2,
> we insert k =
>   Sqrt[11] by hand in the same DE above and work out the values for \
> the same points again.  We get
>
> In[144]:=
> s11 = NDSolve[{(y11^\[Prime]\[Prime])[x] + Sqrt[ 11] y11[x] == 0,
>      y11[0.1] == 0, Derivative[1][y11][0.1] == 1/10^6},
>     y11, {x, 1, 10}];
>
> In[145]:= {y11[1.0], y11[2.0]} /. s11
>
> Out[145]= {{5.47931*10^-7, -1.68202*10^-7}}
>
> Out[105]= {{5.47931*10^-7, -1.68202*10^-7}}
>
> For x = 3, 4, 5, k = Sqrt[10]. We get
>
> In[146]:=
> s11 := NDSolve[{(y11^\[Prime]\[Prime])[x] + Sqrt[10] y11[x] == 0,
>      y11[0.1] == 0, Derivative[1][y11][0.1] == 1/10^6},
>     y11, {x, 1, 10}];
>
>
>
> In[147]:= {y11[3], y11[4], y11[5]} /. s11
>
> Out[147]= {{-5.30318*10^-7, 3.34051*10^-7, 4.16315*10^-7}}
>
> Qn : Should  the values for  y11[1-5] be any different from that calculated earlier ie  y1[1-5]?
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web