cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Translate the entire conversation x

No solution found on solve block, but root function solve the equation.

davidlimtw
8-Gravel

No solution found on solve block, but root function solve the equation.

Hi All,

 

I set up an solve block looking to solve a few equation, however the no solution can be found in solve block but when I use root fuction, I manage to get some answers. What have I done wrong? Can anyone spot the problem, please help. Also how do I get rid of the NaN number i.e. 0.6i on some answer in the root function.

 

davidlimtw_2-1688652316560.png

 

davidlimtw_3-1688652360644.png

 

 

 

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:davidlimtw)


@davidlimtw wrote:

Hi Werner,

 

is this the correct function to make the non real number zero?

 


No, if the goal is to only replace every non-real number by zero.
For example if the non-real number is (0.3+0.6i) m, then its replace  by the positive real part 0.3 m by your approach and  not by zero.

Your approach works as long a the real parts are all negative like in (-0.3 +0.6i) m which may be the case  for your example.

Furthermore your approach additionally replaces all negative real values by zero. Not sure if that was intended.

If you really just want to replace every non-real value by 0, you could do it that way

Werner_E_0-1688661144196.png

 

What your approach actually does is using just the real part of the solution

Werner_E_1-1688661741130.png

and the replacing negative values by zero, no matter if the solution was non-real or real.

 

BTW, if you wish to suppress non-real solutions altogether you can replace the 0 m in my first approach by a NaN, so these values aren't plotted at all.

Werner_E_2-1688661952541.png

And in case you want to suppress non-real values but additionally want to replace negative real values by 0m, you could do it that way

Werner_E_0-1688662219538.png

 

 

View solution in original post

5 REPLIES 5
Werner_E
25-Diamond I
(To:davidlimtw)

The solutions seem to be non-real.
And a solve block will only return non-real solutions if the guess value is non-real! So change the guess to something like (1+1i) m or just 1i m and you will see solutions.

Werner_E_0-1688654496912.png

 

On contrary the root function gives you non-real results even if the guess value is just real.

But the root function returns the very same solutions as the solve block.

Werner_E_0-1688655956061.png

 

And ALL of them are non-real! We can see the the solve block does not find a single result for any of the over 11000 values of S if we provide a real guess value.
BTW, function definitions should be moved out of the solve block and you already have above the block anyway

When called with vector of values as in your case, the solve block would immediately fail when  the first time no solution is found. But we can feed the values of S singly in the solve block and use try and catch to deal with the "no solution found" error. That way  we can check if eventually there are some S-values which yield a real solution. There are none!

Werner_E_1-1688656335092.png

Of course we could have checked  much easier (and faster) that all 11131 solutions are non-real:

Werner_E_2-1688656518150.png

 

 

 

Werner_E
25-Diamond I
(To:davidlimtw)

Addendum to the above:

The reason you get the results with your function using the root() function is a strange behavior of the max() function when non-real values are used:

Werner_E_0-1688657370778.png

 

And when you use delta[5 instead of delta[1, about half of the solutions are real

Werner_E_1-1688657664211.png

 

 

 

Hi Werner, 

 

 Is there a function to make the non-real values to zeros? 

Hi Werner,

 

is this the correct function to make the non real number zero?

davidlimtw_0-1688659657400.png

 

 

Werner_E
25-Diamond I
(To:davidlimtw)


@davidlimtw wrote:

Hi Werner,

 

is this the correct function to make the non real number zero?

 


No, if the goal is to only replace every non-real number by zero.
For example if the non-real number is (0.3+0.6i) m, then its replace  by the positive real part 0.3 m by your approach and  not by zero.

Your approach works as long a the real parts are all negative like in (-0.3 +0.6i) m which may be the case  for your example.

Furthermore your approach additionally replaces all negative real values by zero. Not sure if that was intended.

If you really just want to replace every non-real value by 0, you could do it that way

Werner_E_0-1688661144196.png

 

What your approach actually does is using just the real part of the solution

Werner_E_1-1688661741130.png

and the replacing negative values by zero, no matter if the solution was non-real or real.

 

BTW, if you wish to suppress non-real solutions altogether you can replace the 0 m in my first approach by a NaN, so these values aren't plotted at all.

Werner_E_2-1688661952541.png

And in case you want to suppress non-real values but additionally want to replace negative real values by 0m, you could do it that way

Werner_E_0-1688662219538.png

 

 

Announcements

Top Tags