3
$\begingroup$
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

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

2 Answers 2

0
$\begingroup$

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.

In response to OP's comments.

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}]

enter image description here

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}]
$\endgroup$
6
  • $\begingroup$ 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 $\endgroup$
    – Kendall
    Mar 5, 2017 at 13:51
  • $\begingroup$ @KennyB See the edit. $\endgroup$
    – zhk
    Mar 5, 2017 at 14:01
  • $\begingroup$ 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 ? $\endgroup$
    – Kendall
    Mar 5, 2017 at 14:14
  • $\begingroup$ 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. $\endgroup$
    – Kendall
    Mar 5, 2017 at 14:19
  • $\begingroup$ @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 . $\endgroup$
    – zhk
    Mar 5, 2017 at 14:38
1
$\begingroup$

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}]

uplot

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

vplot

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.