Skip to main content
10-Marble
October 17, 2023
Solved

Odesolve "This value must be a function" error

  • October 17, 2023
  • 2 replies
  • 60880 views

Good evening, everyone.

 

I was working on a model in Mathcad today. Unfortunately, I keep getting an error message every time. To prevent errors, I have removed all units. I have double-checked the function, but I can't seem to find the error. The error message I'm getting is "This value must be a function." I would say that this might be in the theta1(t), z2(t), and theta2(t).

 

I have already reviewed the steps below:

  1. Check the ODEs: Make sure that the ODEs you are trying to solve are properly defined as functions of the independent variable (usually time) and dependent variables. For example, if you have an ODE like dy/dt = f(t, y), make sure that f(t, y) is a valid function.

  2. Correct Function Format: Ensure that the functions used in your ODEs are defined correctly. Mathcad Prime requires well-defined functions with proper syntax. Double-check your function definitions, including parameter lists and mathematical expressions.

  3. Function Inputs: Confirm that you are passing the correct arguments to the Odesolve function. The first argument should be a vector of ODEs, the second argument should be the list of dependent variables, and the third argument should be the initial conditions.

  4. Units and Dimensions: Verify that the units and dimensions of your equations are consistent. In Mathcad Prime, inconsistencies in units can cause errors. Ensure that all units match up correctly.

I think I've probably made a small mistake, but I can't find it

 

Thank you in advance for your help, and I appreciate your assistance. 

 

Best answer by Werner_E

I can't contribute anything technically to the task, so just two final comments on the last plot and why it can't work in Prime:

1) You defined the solve block which amongst others also defines the function x.1 tu run from 0 to t.end=2:

Werner_E_0-1700074264528.png

This means that the argument of the function x.1 can only be a value in the interval from 0 to 2. You can't expect any meaningful result if you feed an argument greater than 2

Werner_E_1-1700074380282.png

The first trace in the last plot you tried to create used a range tau.1 = 0, 5 .. 315 and tried to plot x.1(tau.1). But x.1 is only defined for the first value (0) in that range, the next one (5) does not return a value as shown above. This means that this first trace would consist of just one point at position 0. I changed the color of the trace to red and a large "line" width so you can see that point:

Werner_E_2-1700074658259.png

 

2) The second trace in that very same last plot has the range tau.1 at the abscissa and f(x.1) at the ordinate.

You defined the function f using x.1 as formal argument. This might not be the best idea because the name x.1 is already used for a function defined by the solve block, but its not a mistake/error and it works without problems and as expected and you sure can plot that function without any difficulties, here with an actual argument named ttt in a quickplot (= plotting without defining a specific range for ttt)

Werner_E_3-1700074845856.png

But in the plot you created you have still tau.1 at the x-axis and use x.1 as actual argument when you place f(x.1) at the y-axis.
But x.1 is the function defined by your solve block and not a variable. With this combination (unused variable tau.1 and function x.1 as argument of function f), Prime can't possibly know what exactly it's supposed to plot (and I wouldn't know either) 😉

It would be possible to create a plot if you write f(x.1(tau.1)), but here again you would run into the same problem as already explained for the first trace - the plot would only consist of one single point.

 

I wish you all the best for your health and every success in completing your task.

2 replies

10-Marble
October 18, 2023

Solved

 

It worked, super happy, of course, being a Mathcad novice .The error was in the notation of inertia. Learn from this how to troubleshoot as well.

Can this topic remain open? I want to model the backlash of the gears. I'm trying to do in Mathcad what I used to do in MATLAB. Anyway, thanks to those who reviewed it

ttokoro
21-Topaz I
21-Topaz I
October 18, 2023

Theta1' doesn't start from 0. ???  So still it has some error.

 

image.pngimage.png

t.t.
25-Diamond I
October 18, 2023

@ttokoro wrote:

Theta1' doesn't start from 0. ???  So still it has some error.

 


No, no error - just numerical inaccuracies.

Adjust the end value (75 -> 0.5) and you may also increase the number of intervals from default 10^3 to something larger:

Werner_E_0-1697639333146.png

I guess the 75 originally were meant to be milliseconds.

Here without a log-scaled abscissa:

Werner_E_0-1697646894878.png