# Saving DSolve results [duplicate]

DSolve[{u''''[x] == 0, v''''[x] == (1/(a*Sqrt[π]))*Exp[-x^2/a^2],
u[0] ==  0, u'[0] == 0,  v''[1] == 0, v'''[1] == 0, u[b/H] == v[b/H],
u'[b/H] == v'[b/H], u''[b/H] == v''[b/H], u'''[b/H] == v'''[b/H]},
{u, v}, x]


How do I save both these functions from the output separately so I can graph them separately? I thought they would be automatically saved as u[x], v[x] but this isn't the case. I also found guides on how to save one function using dsaad[x_] = u[x] /. First @ DSolve but this doesn't work for 2 functions

• The answer to this question is basically the same as to this post: Assign the results from a Solve to variable(s) Mar 5, 2017 at 12:59
• @Artes The problem is that those save values, where here I need to save entire functions. Dependent on all the variables. Mar 5, 2017 at 13:10
• It doesn't matter, this way you can save functions as well. Mar 5, 2017 at 13:19

I like the approach suggested by @m_goldberg but here is another way you can do it.

sol = DSolve[...]
ux = FullSimplify[u[x] /. sol][[1]]
vx = FullSimplify[v[x] /. sol][[1]]


Remember, for some expressions FullSimplify maybe very time consuming. [[1]] is to remove the curly brackets around the expression.

To plot the two solutions, you will need to specify numerical values for the parameters a, b and H. BTW, it is not a good practice to use single capital letters.

To have a plot, I assigned random values for the parameters.

Plot[ {ux /. {a -> 5, b -> 2, H -> 1}, vx /. {a -> 5, b -> 2, H -> 1}}, {x, 0, 10},
Frame -> True, PlotStyle -> {Red, Green}]


You can manipulate your plot like this,

Manipulate[ Plot[{ux /. {a -> a1, b -> b1, H -> H1}, vx /. {a -> a1, b -> b1, H -> H1}},
{x, 0, 10}], {a1, 1, 5}, {b1, 1, 5}, {H1, 1, 5}]

• Thank you. I'm actually having troubles getting it to plot. Will try your method and see if it works. I know sometimes Mathematica is fussy Mar 5, 2017 at 13:51
• @KennyB See the edit.
– zhk
Mar 5, 2017 at 14:01
• Ah thanks !! Yeah I know capital letters aren't great. It's a bad habit. I'm assuming this will work with manipulate plot ?Because that is what I have been doing. If not I really don't mind assigning values. The ux /. is important ? That's where you are "evaluating" it at right ? Mar 5, 2017 at 14:14
• Also, interestingly, those values for a,b,H should not have resulted in those graphs. You may have found something for me to add to my paper. Mar 5, 2017 at 14:19
• @KennyB I don't know nothing about the physics of these equations, since you haven't provided any. Nevertheless, I am happy that my response is helping you .
– zhk
Mar 5, 2017 at 14:38

If you have V10 or later, you can use DSolveValue which returns the function rather than rules.

{uF, vF} = DSolveValue[...]


Uf and Vf can be used just any built-in function. For older version of Mathematica, you can use

{uF, vF} = DSolve[...][[1, All, 2]]


which extracts the functions from the rules and gives the same result as DSolveValue.

### Plotting

paraUF[aa_, bb_, h_][x_] = N[uF[x] /. {a -> aa, b -> bb, H -> h}];
paraVF[aa_, bb_, h_][x_] = N[vF[x] /. {a -> aa, b -> bb, H -> h}];


Plot[paraUF[1, 2, 3][x], {x, -10, 10}]


Plot[paraVF[1, 2, 3][x], {x, -10, 10}]


• Thank you, just what I needed, now I'm just trying to get the plot working. Mar 5, 2017 at 13:46
• @KennyB. See update on plotting. Mar 5, 2017 at 14:43
• Thank you, these are so useful !! Mar 5, 2017 at 14:53
• @KennyB. I'm happy that you find my answer useful, but I'm surprised that you accepted the other answer. Mar 5, 2017 at 15:11
• (+1)@m_goldberg my answer in essence is yours, because whatever I know about Mathematica, I learn it from you guyz. Thankyou
– zhk
Mar 5, 2017 at 15:17