0
$\begingroup$

In one cell, I have

ClearAll[A, B, U, V]
rhs[x] := A - B*(1 - Exp[U[x]/V])
DSolve[U'[x] == A - B*(1 - Exp[U[x]/V]), U[x], x] // FullSimplify
DSolve[{U'[x] == A - B*(1 - Exp[U[x]/V]), U[0] == 0}, U[x], 
  x] // FullSimplify

Where I get proper results. I then want to do this numerically and plot U(x). In a new cell, I do

ClearAll[c, UBar, A, V, h]
a = 0.5;
c = 0.01;
UBar = 0.1;
A = 0.09; (* delta(1-UBar)*)
V = V /. Solve[0 == -c + (1 - Exp[-a*UBar/V]), V];
h = V*(1 - Exp[-a*UBar/V]);
DSolve[{U'[x] == A - h*(1 - Exp[U[x]/V])}, U[x], x]
U[x_] = U[x] /. 
   DSolve[{U'[x] == A - h*(1 - Exp[U[x]/V]), U[0] == 0}, U[x], x];

and the output is just

Hold[DSolve[{Derivative[1][U][x] == A - h (1 - Exp[U[x]/V])}, U[x], 
  x]]

Why?

$\endgroup$
  • 1
    $\begingroup$ You somehow didn't notice (or forgot to mention) the huge number of messages also produced as output, including several stating that your input is erroneous and a good number of $RecursionLimit::reclim messages. Hitting this recursion limit is where the Hold comes from. I recommend you correct your inputs as suggested by the messages. $\endgroup$ – Oleksandr R. Sep 20 '15 at 17:44
  • $\begingroup$ @OleksandrR. I'm not getting any of those messages... do I need to setup something? I'm using a freshly downloaded Mathematica version on trial. $\endgroup$ – FooBar Sep 20 '15 at 18:37
  • $\begingroup$ That is very worrying, then. The output should look like this. That is how it comes out by default, so I doubt if you would need to make any specific settings. Perhaps something about the trial installation is broken? Be warned that if this does not work, other problems may also exist with your installation. $\endgroup$ – Oleksandr R. Sep 20 '15 at 18:46
  • $\begingroup$ What is your Messages setting in your Preferences? Maybe they are turned off or redirected.... $\endgroup$ – Michael E2 Sep 20 '15 at 21:07
2
$\begingroup$

Noting my edits:

a = 0.5;
c = 0.01;
UBar = 0.1;
A = 0.09;(*delta(1-UBar)*)
v = V /. Solve[0 == -c + (1 - Exp[-a*UBar/V]), V] // First;
h = v*(1 - Exp[-a*UBar/v]);
(*DSolve[U'[x]\[Equal]A-h*(1-Exp[U[x]/v]),U[x],{x,0,1}]*)
sol = NDSolve[{U'[x] == A - h*(1 - Exp[U[x]/v]), U[0] == 0}, U[x], {x, 0, 73}];

Plot[U[x] /. sol, {x, 0, 73}]

enter image description here

With DSolve you get an error message:

DSolve[U'[x] == A - h*(1 - Exp[U[x]/v]), U[x], {x, 0, 1}]

Factor::lrgexp: Exponent is out of bounds for function Factor.

$\endgroup$
2
$\begingroup$

Alternatively, U can be computed with NSolve before specifying the constants.

ClearAll[c, UBar, A, U, V, h] 
W[x_] = U[x] /. DSolve[{U'[x] == A - h*(1 - Exp[U[x]/V]), U[0] == 0}, U[x], x][[1]]
    //FullSimplify
(* A x - (A V Log[A])/(A - h) - 
   V Log[(A^(A/(-A + h)) (A E^((h x)/V) - E^((A x)/V) h))/(A - h)] *)

Then, if desired, the constants can be introduced and W further simplified.

a = 0.5; c = 0.01; UBar = 0.1; A = 0.09;(*delta(1-UBar)*)
V = V /. Solve[0 == -c + (1 - Exp[-a*UBar/V]), V][[1]]
h = V*(1 - Exp[-a*UBar/V])

W[x] // Simplify
(* 26.786 + 0.09 x - 4.97496 Log[487.29 E^(0.01 x) - 269.361 E^(0.0180906 x)] *)

Plotting this last expression gives the curve in Willinski's answer.

Comments on original code in the question

The original code has two problems. First, the expression for v produces {4.97496}, and the brackets cause DSolve to choke. They can be eliminate by appending [[1]] (or //First, as used by Willinski) to the expression. Second, using U[x_] = U[x] /. DSolve[... is dangerous, inviting recursion issues that occur the second time the code is run. Adding U to ClearAll prevents the recursion, but this construct still is not good practice. For that reason, I use w on the left side of the expression in my answer.

Even after these items are corrected, the code still produces the error message,

Factor::lrgexp: Exponent is out of bounds for function Factor. >>

This looks like a Mathematica bug to me.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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