Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NDSolve and error

85 views
Skip to first unread message

dod...@poczta.fm

unread,
Oct 4, 2008, 6:16:53 AM10/4/08
to
Hello!
Lately I wrote simple code in Mathematica

sol[p_] :=
NDSolve[{Sqrt[
1 + (y'[t])^2] == (x^(p - 1) + (y[x])^(p - 1)*y'[x])/(x^p +
y[x]^p)^(1 - 1/p), y[1] == 6}, y, {x, 1, 4}]

but when I typed sol[2] the following kind of error was shown:

NDSolve::"ndnum": "Encountered non-numerical value for a derivative at
\
\!\(x\) == \!\(4.587812868332132`*^-296\)."

May I know what I'm doing wrong? Or how can I improve that code to
work correctly?
Thank you in advance
John

dod...@poczta.fm

unread,
Oct 5, 2008, 2:23:15 AM10/5/08
to

dod...@poczta.fm

unread,
Oct 5, 2008, 5:37:42 AM10/5/08
to

pratip

unread,
Oct 5, 2008, 11:48:55 PM10/5/08
to
I think u typed wrongly the equation.
I corrected it like this

sol[p_] :=
NDSolve[{Sqrt[
1 + (y'[t])^2] == (t^(p - 1) + (y[t])^(p - 1)*y'[t])/(t^p +
y[t]^p)^(1 - 1/p), y[1] == 6}, y, {t, 1, 4}]
Then
ol = sol[2];
Plot[y[t] /. ol, {t, 1, 4}]

Bill Rowe

unread,
Oct 5, 2008, 11:49:05 PM10/5/08
to
On 10/4/08 at 6:16 AM, dod...@poczta.fm wrote:

>Hello! Lately I wrote simple code in Mathematica

>sol[p_] :=
>NDSolve[{Sqrt[ 1 + (y'[t])^2] == (x^(p - 1) + (y[x])^(p -
>1)*y'[x])/(x^p + y[x]^p)^(1 - 1/p), y[1] == 6}, y, {x, 1, 4}]

>but when I typed sol[2] the following kind of error was shown:

>NDSolve::"ndnum": "Encountered non-numerical value for a derivative
>at \ \!\(x\) == \!\(4.587812868332132`*^-296\)."

>May I know what I'm doing wrong? Or how can I improve that code to
>work correctly?

Look at the left hand side of differential equation you posted.
It says something about the derivative evaluated at t. But the
right hand side is evaluated at x. Change the t on the left hand
side to x and things should work.

Peter Pein

unread,
Oct 5, 2008, 11:49:48 PM10/5/08
to
dod...@poczta.fm schrieb:

Hi John,

try to replace y'[t] in the call to Sqrt by y'[x], and you'll get an exact
solution for p=2:
In[3]:= DSolve[{Sqrt[Derivative[1][y][x]^2 + 1] ==
(x^(p - 1) + y[x]^(p - 1)*Derivative[1][y][


x])/(x^p + y[x]^p)^(1 - 1/p),

y[1] == 6} /. p -> 2, y, x]
Out[3]= {{y -> Function[{x}, 6*x]}}

Peter

Jean-Marc Gulliet

unread,
Oct 6, 2008, 12:16:10 AM10/6/08
to
dod...@poczta.fm wrote:

> sol[p_] :=
> NDSolve[{Sqrt[
> 1 + (y'[t])^2] == (x^(p - 1) + (y[x])^(p - 1)*y'[x])/(x^p +

=================^^^^^^
Must be y'[x] not of t.

> y[x]^p)^(1 - 1/p), y[1] == 6}, y, {x, 1, 4}]
>
> but when I typed sol[2] the following kind of error was shown:
>
> NDSolve::"ndnum": "Encountered non-numerical value for a derivative at
> \
> \!\(x\) == \!\(4.587812868332132`*^-296\)."

In[1]:= sol[p_] :=
NDSolve[{Sqrt[
1 + (y'[x])^2] == (x^(p - 1) + (y[x])^(p - 1)*y'[x])/(x^p +


y[x]^p)^(1 - 1/p), y[1] == 6}, y, {x, 1, 4}]

In[2]:= sol[2]

Out[2]= {{y->InterpolatingFunction[{{1.,4.}},<>]}}

In[3]:= Plot[y[x] /. %, {x, 1, 4}]

Regards,
-- Jean-Marc

Bob Hanlon

unread,
Oct 6, 2008, 12:17:39 AM10/6/08
to
You typed y[t] rather than y[x]


Bob Hanlon

---- dod...@poczta.fm wrote:

=============


Hello!
Lately I wrote simple code in Mathematica

sol[p_] :=


NDSolve[{Sqrt[
1 + (y'[t])^2] == (x^(p - 1) + (y[x])^(p - 1)*y'[x])/(x^p +

y[x]^p)^(1 - 1/p), y[1] == 6}, y, {x, 1, 4}]

but when I typed sol[2] the following kind of error was shown:

NDSolve::"ndnum": "Encountered non-numerical value for a derivative at
\
\!\(x\) == \!\(4.587812868332132`*^-296\)."

May I know what I'm doing wrong? Or how can I improve that code to


work correctly?
Thank you in advance
John


--

Bob Hanlon


M.G. Bartlett

unread,
Oct 6, 2008, 4:31:40 AM10/6/08
to
On Oct 5, 12:16 am, doda...@poczta.fm wrote:
> Hello!
> Lately I wrote simple code in Mathematica
>
> sol[p_] :=
> NDSolve[{Sqrt[
> 1 + (y'[t])^2] == (x^(p - 1) + (y[x])^(p - 1)*y'[=
x])/(x^p +
> y[x]^p)^(1 - 1/p), y[1] == 6}, y, {x,=

1, 4}]
>
> but when I typed sol[2] the following kind of error was shown:
>
> NDSolve::"ndnum": "Encountered non-numerical value for a derivative at
> \
> \!\(x\) == \!\(4.587812868332132`*^-296\)."
>
> May I know what I'm doing wrong? Or how can I improve that code to
> work correctly?
> Thank you in advance
> John

John,

I think your error results from the fact that you have defined y as
both a function of x and as a function of t (y[t] and y[x]). I am not
certain if you meant for y to be a function of both (in which case you
need to specify it as such (y[x,t]) throughout the equation (and
specify which derivatives you are taking) or if the y[t] on the left
side of your differential equation should be a y[x] (leaving you with
a tractable ordinary differential equation). Hope that helps,

Marshall

dod...@poczta.fm

unread,
Oct 7, 2008, 7:07:29 AM10/7/08
to
Hello!
Thanks for all your tips. It turned out that was my silly mistake
(should be y[x], not y[t]) but sometimes such mistakes are the most
difficult to find.
Best regards
John

0 new messages