Message Boards Message Boards

[?] Plot DSolve equation by ListPlot ?

Posted 7 years ago

Hi

I want to use ListPlot to show the answers of DSolve equation at A < x < B , the code that i written does not work , please help me .

Thanks

H = DSolve[{u''''[x] + u''[x] + u[x] == 0, u[0] == 1, u'[0] == 2, 
    u[1] == 3, u'''[1] == 5}, u[x], x];
d = Table[H[x], {x, 2}];
ListPlot[d]
POSTED BY: Saleh Baradaran
2 Replies
Posted 7 years ago

Do you think this works for you

sol = Flatten@ DSolve[{u''''[x] + u''[x] + u[x] == 0, u[0] == 1, u'[0] == 2,  u[1] == 3, u'''[1] == 5}, u[x], x];

Plot[u[x] /. sol, {x, 1, 10}]

d = Table[u[x] /. sol, {x, 1, 10}] // N    

ListPlot[d]
POSTED BY: Okkes Dulgerci

Hi,

I would strongly discourage creating a list from the solution of the ODE. Mathematica gives you in this case the analytical solution that you can plot directly.

H = DSolve[{u''''[x] + u''[x] + u[x] == 0, u[0] == 1, u'[0] == 2, u[1] == 3, u'''[1] == 5}, u[x], x];

Note that you shouldn't use variable or function names starting with a capital - it is customary to avoid capitalisation for user defined functions. I use your capital H here to stay as close as possible to your question.

Here is how you plot the solution:

Plot[u[x] /. H[[1]], {x, 0, 10}]

enter image description here

Mathematica takes care of plotting it. You can also calculate derivatives and many other things. Now if you insist on using ListPlot (emulating perhaps other programming languages) you can do this like so:

ListPlot[Table[{x, u[x] /. H[[1]]}, {x, 0, 10, 0.1}]]

enter image description here

But it is weird to evaluate a perfectly good function at some discrete points and then plot the table, in particular if you have a tool as powerful as Mathematica.

Best wishes, Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract