Skip to main content
3-Newcomer
August 7, 2023
Solved

My first mathcad worksheet- many glitches

  • August 7, 2023
  • 2 replies
  • 3797 views

I am using Mathcad Prime 5.0.0.0, Windows 11, for the first time as instructor in a civil engineering course having taken over from the previous instructor mid-semester.  (Ordinarily I use Matlab.)  My worksheet is supposed to solve the differential equation for liquid spilling out of a small hole in a tank modeled by the ODE dh/dt=-K*sqrt(h) in two ways: odesolve and rkfixed.  Here are the glitches I encountered:

 

1. Plotting functions h(t) (the exact closed-form solution) and q(t) (the output from odesolve) did not work for me.  I received an error message about complex or infinite values.  However, it is clear from its formula that h(t) cannot take on infinite or complex values.  In addition, Mathcad repeatedly changed the units of the t axis from s (which I typed) to 1/s * s, which is incorrect.

 

2. The exact solution to the problem exists and is well defined up to about t=85000,  After that point, the tank is empty and the ODE is undefined.  However, odesolve was able to integrate only to about t=60000.  See the glitch with z(t) in the attached worksheet.

 

3,  I also solved the IVP with rkfixed.  The units came out incorrectly.  The dependent variable column of the output was labeled m*s instead of m.

 

I'd appreciate any help since I need to hand out this assignment soon.  I've attached my worksheet.

Best answer by Werner_E

@KP_10752086 wrote:

Thank you! It looks like something good was done in v. 11.

That for sure. The old Mathcad 11 is considered by many users as being the best Mathcad version ever built. This opinion is based to a good part on the fact, that in this version there still is integrated a slimmed down version of Maple for the symbolic operations.

I have tried your odesolve block in Prime without units with no success and the same ODE also fails in Mathcad 15 with the error message "This function cannot be used here" without indicating which function this text refers to.
BTW, of course the solve block fails in the current Prime 9, too - so the problem still is not fixed.

2 replies

23-Emerald IV
August 7, 2023

1. You did not define t. Hence Prime uses its automatic definition, which is from -10 to 10, without units.

If you define t as (e.g.):

LucMeekes_0-1691440884919.png

before the plot, then it plots as expected.

 

Success!

Luc

3-Newcomer
August 7, 2023

Great, thanks! This fixed obtaining plots. Do you know the answer to my other questions as well?

23-Emerald IV
August 7, 2023

No.

In (real) Mathcad 11 the odesolve runs just fine:

LucMeekes_0-1691445584007.png

I've checked Prime 7 and 8, they both quit at (about):

LucMeekes_1-1691445614187.png

where

LucMeekes_2-1691445664415.png

I have no clue as to why.

Maybe someone with Prime 9 can check....

Success!
Luc

 

25-Diamond I
August 7, 2023

Your first question is already answered by Luc. You can't use the quickplot feature (plotting without defining the abscissa variable) with units - you have to define a range with units for the abscissa values.

I would add, that you may consider formatting the abscissa as hours instead of seconds. You should also know that on each axis you can edit the first, second and last scale value (can be quite a fiddling around). This is often necessary as Primes auto-scaling not exactly the best you can imagine.

 

I am not sure but the OdeSolve() block seems to fail because of numerical round-offs / inaccuracies. It looks like the numerical value of z (or q) is getting negative and so its the root which actually throws this error.
You may consider one of the two workarounds you can see in the picture:

Werner_E_0-1691448360214.png

The differences can be seen in the next pic and I guess its in a region which is not of interest to you anyway

Werner_E_2-1691448434659.png

 

In the workaround the "max" function could also be replaced by q*(t)=-K*Re(sqrt(q(t)) with the same effect.

 

The wrong unit returned by rkfixed is strange.

According to the help (the example there) the initial value should be a vector (a 1x1 vector in your case).
Providing this 1x1  vector instead of a simple scalar cures the wrong units problem (have no idea as to why it does, though).

Werner_E_3-1691448610641.png

The same example in the help
-> Example: Solving a First-Order ODE Initial Value Problem

also treats the second argument of the vector function as a vector even in case of a single function first order ODE

Werner_E_4-1691448813922.png

But this seems not to matter as your sheet is working both ways

Werner_E_5-1691448851594.png   or    
Werner_E_6-1691448864942.png

 

Worksheet in format Prime 5 attached

 

3-Newcomer
August 8, 2023

Interesting. I knew the solution might become negative due to roundoff near the end, which is why I ended rkfixed at tend-1000s. I guess I don't know what odesolve does. Is it symbolic?

Thank you.