Mathematica output seems incorrect

In summary: The Reduce function can generate three solutions for (Vs) that use the Root[] function.3: All three solutions generated by the Reduce function use the Root[] function, but only one of the solutions actually produces a valid result when plugged into the equation on the image.
  • #1
larsbentley
29
0
I am using Mathematica to create a formula to solve for (Vs) in an equation shown at the top of the attached image. Using the assumptions shown, Mathematica outputs three possible solutions, all of which appear to be incorrect when I check them using actual values.

I get this error when Mathematica generates the three possible solutions :

"Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result."

...and I believe this may be the cause of the problem, but I have no idea how to get around this.

If I plug sample values into the original equation (as shown at the bottom of the attached jpg) it will produce a valid result (596.704) as the third possible solution.

If I plug these same values into the second of the three long equations Mathematica has given me it will produce a value for (Vs) that is very close to correct (596.7044277254138 - 3.67761*10^-15 I), but includes an additional small imaginary number

Does anyone have experience with Mathematica that may help me produce a valid equation to solve for (Vs)?

(Vs) is peak velocity in a trapezoidal move, while (Vi) is initial velocity, which is always greater than zero for my purposes. (Ma) is counts of acceleration, (Md) is counts of deceleration, (d) is counts of total distance , (t) is total time. Final velocity is always assumed to be zero, so it is not shown in the original formula.

Original formula:

Assuming[Vs \[Element] Reals; d > 0; t > 0; Vi > 0; Vs > 0; Ma > 0;
Md < 0;, Solve[ d == ((Vs + Vi)/2)*((Vs - Vi)/(.5*Vs^2/Ma)) + ((Vs/2)*(-Vs/(.5*Vs^2/Md))) + (Vs*(t - (-Vs/(.5*Vs^2/Md)) - ((Vs - Vi)/(.5*Vs^2/Ma)))), Vs]]

Thanks,

Lars
 

Attachments

  • mathematica output.jpg
    mathematica output.jpg
    52.5 KB · Views: 655
Last edited:
Physics news on Phys.org
  • #2
I used the Reduce function on my on my source equation the output gives three solutions for (Vs) that use the Root[] function.

The first solution gives the correct answer for my purposes when I refine it using a set of actual values in place of the variables.

I don't really understand what Root[] is doing enough to know what to do with this information, or how to rewrite this as a formula that I can use to solve for (Vs). Can anyone explain Root[] to me or re-write this in another format?

Thanks
 

Attachments

  • mathematica root output.jpg
    mathematica root output.jpg
    7.5 KB · Views: 678
  • mathematica reduce output.jpg
    mathematica reduce output.jpg
    8.6 KB · Views: 662
  • #3
If you attach a small Mathematica notebook that is simplified down to where it clearly shows what your difficulty is and just what calculation you want to have done or what result is incorrect then I think you are much more likely to get some good help than if you post some jpg file that anyone trying to help will likely have to type all back into verify their efforts and to triple check to make sure they didn't introduce any new errors by typing all your code back in.

If, unless you are specifically dealing with a numerical analysis problem, you stop inserting decimal points and instead use exact fractions I think you will far more likely get sensible results from a number of different Mathematica functions. Only in a recent version update of Mathematica did Reduce stop crashing Mathematica or failing to give an answer when it was given some equations including decimal points. Calculators use decimal points, FORTRAN uses decimal points, Mathematica will often be much more understanding when you use 1/2 instead of 0.5.

With a small clean notebook pointing out exactly where the problem is and what all the values of your parameters are and what you want the answer to be I will be happy to take a few minutes to try to track down what when wrong.
 
  • #4
Bill,

Thanks so much, I should have done that to start with. I have attached a notebook showing the original formula I was using(the formula using 0.5 instead of a fraction).

I want Mathematica to solve for Vs so I can write out this new formula as part of programming a human-machine-interface that commands a motion controller.

This notebook shows the three resulting formulas, none of which worked when I plugged in test values. The formula that came closest is shown in the second input in the notebook.

The third input in the notebook shows the same sample values plugged into the original formula, showing a valid result for Vs as the third possible solution.

A couple rules: Vi is always greater than zero, and Md is always a negative number. (Md) and (Ma) added together must not total more than (d).

Thanks again. This is my first time using Mathematica so I'm still just figuring out the basics.


Lars
 

Attachments

  • assumptions main formula3.nb
    39.5 KB · Views: 526
  • #5
Ok, that's better.

1: Some Mathematica users believe "Assuming" has more power than it often has. Assuming is only a hint that is used by some functions in Mathematica and ignored by other other functions. So don't assume that Assuming even has any common sense. In particular that often doesn't force Solve to throw away complex solutions just because you tell Assuming that the variable of interest is in the Reals.

2: Mathematica uses semicolons differently from almost all other programming languages and it is completely intolerant of different uses. So what you did was Assuming[d>0;t>0...,Solve[]]. That needs to be Assuming[d>0&&t>0&&...,Solve[]]. I don't remember at the moment, but you might be able to also use Assuming[{d>0,t>0...},Solve[]]. But you cannot use semicolons the way you did.

3. Let's make more sense of your problem. You have a complicated expression you are trying to solve with lots of common terms and fractions. Can this be any simpler and thus let us see what is going on?

Expand[((Vs + Vi)/2)*((Vs - Vi)/(1/2*Vs^2/Ma)) + ((Vs/2)*(-Vs/(1/2*Vs^2/Md))) + (Vs*(t - (-Vs/(1/2*Vs^2/Md)) - ((Vs - Vi)/(1/2*Vs^2/Ma))))]

gives me

-Ma + Md - (Ma*Vi^2)/Vs^2 + (2*Ma*Vi)/Vs + t*Vs

Ah, much simpler and more understandable. You want to Solve for Vs, you have that squared in a denominator and not squared in a numerator. That whispers "cubic equation in Vs" to me. That explains why you are getting three solutions, every cubic has three of those.

Vs/.Solve[d==-Ma + Md - (Ma*Vi^2)/Vs^2 + (2*Ma*Vi)/Vs + t*Vs,Vs]

gives me the three solutions. Then

%/. {d -> 10000, t -> 20, Vi -> 20, Ma -> 1000, Md -> -1000}

gives me the three solutions with your parameters. Then

%//N

gives me decimal approximations. Then

Chop[%]

gives me the decimal approximations with tiny roundoff complex parts trimmed.

And the real answer is 596.704. The other two are complex conjugates you don't want.

Does this explain it?
 
  • #6
Thank you so much, that clears up quite a lot. The formula I need is much cleaner now and I've got a better handle on how to input what I want. I do have one more problem...perhaps you might have some advice on.

I need to write up the correct formula in a programming language that doesn't have provisions for imaginary numbers, which are used by the correct formula. Is there an alternate method for describing the "i" imaginary number mathematically that I might use to write up the formula?

Thanks much,

Lars
 

1. Why is my Mathematica output different from what I expected?

There could be several reasons for this. One possibility is that there is an error in your code or input. You may need to double-check your syntax and ensure that all variables and functions are defined correctly. Another possibility is that there is a bug in the Mathematica software. In this case, you can report the issue to Wolfram Support for assistance.

2. How do I know if my Mathematica output is correct?

The best way to verify the correctness of your output is by comparing it to known results or using test cases. You can also consult with other Mathematica users or refer to online resources for confirmation.

3. Why is my Mathematica output in a different format than expected?

Mathematica has many built-in functions and options that allow you to customize the format of your output. Make sure to check the documentation or use the Format menu to adjust the output format according to your preferences.

4. Can I change the precision of my Mathematica output?

Yes, you can use the SetPrecision function to specify the precision of your output. You can also use the N function to round your output to a specific number of digits.

5. How can I improve the performance of my Mathematica output?

If your output is taking a long time to compute, you can try using the Compile function to optimize your code. You can also consider using parallel processing or breaking up your code into smaller chunks to improve performance. Additionally, make sure to close any unnecessary notebooks or programs that may be running in the background.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
Back
Top