Community Tip - You can change your system assigned username to something more personal in your community settings. X
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.
Solved! Go to Solution.
@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
What your approach actually does is using just the real part of the solution
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.
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
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.
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.
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!
Of course we could have checked much easier (and faster) that all 11131 solutions are non-real:
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:
And when you use delta[5 instead of delta[1, about half of the solutions are real
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 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
What your approach actually does is using just the real part of the solution
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.
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