Maple: solve with a variable or fsolve without variable return different result

282 Views Asked by At

I've encountered a very strange issue with Maple. Hopefully to get an answer from here.

The result returns differently with solve and fsolve after/before a variable is given a certain value. See attachment and/or PDF exported from Maple

The result comes from solve (with variable epsilon) returns value of the same variable with imaginary part while the fsolve returns the correct answer.

Now how can I achieve the same result as fsolve via solve?

Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

The error is because of the way you use assign. The output of your solve step is multiple lists on the form

{x = 1, y = 2},{x = 2, z = 3}

If you try to run assign(%) then only the last list will be used. That means x = 2, z = 3 and y will be unassigned.

Instead, get the values of $d_0$ by a sequence call, taking the first element of each list and print it. We have used allvalues because solve was returning expressions involving RootOfs.

sol := solve({eq3, eq4, eq5, eq6}, {d[0], d[1], d[2], d[3]}) assuming epsilon::real:
epsilon := -.1
allvals := allvalues(sol);                     ## Gives all the solutions. 
seq(allvals[i][1],i = 1..numelems([allvals])):
print~([%])[];
d[0] = 9.849912475 - 1.375424440 I
d[0] = 9.600120375
d[0] = 14.45330059
d[0] = 9.849912475 + 1.375424440 I

Alternatively, you can set epsilon before the solve step to avoid the allvalues part.

Note that the fsolve only captures one of the analytic solutions as expected.