## 145 Reputation

10 years, 162 days

## The fsolve command fails, solve doesn't...

Maple 18

Hi Maple community

I'm running an algorithm where a non-linear equation system must be solved, in this case is a 26x26 system.

After 16116 succesful previous computations, fsolve stops giving me results.
I checked why and I was first expecting that, for some reason, the 26x26 system had an error and I ended with something like 25x26 or vice versa. But that was not the case.

So I tried the command solve and it not only worked fine but also gave me two results, but I only need one. I guess I could check for the wrong solution and discard it, but I still wondering why fsolve is failing and if there is anything to help fsolve not to fail.

These are the set of equations if somebody wants to check them:

EQ := W[1, 16117]*(-0.3860115660e-1*HRa[1, 16117]-0.1876793978e-1*ga[1, 16117]+0.7836678184e-1) = 2.040147478*10^6*SR[1, 16118], W[1, 16117]*(-0.3915554290e-1*HRa[1, 16117]-0.1903748329e-1*ga[1, 16117]+0.8260795999e-1) = 3.876387504, W[1, 16117]*(-0.1876794098e-1*HRa[1, 16117]-0.9892449327e-2*ga[1, 16117]+0.3810204607e-1) = 2.040147478*10^6*v[1, 16118], HLa[1, 16117] = .9724029753*ga[1, 16117]+HRa[1, 16117], NRa[1, 16117] = 0.7006679273e-1*HRa[1, 16117]-.1803623678*ga[1, 16117]+1.002451672, NLa[1, 16117] = 0.7006679273e-1*HRa[1, 16117]+.2484955248*ga[1, 16117]+1.002451672, SL[2, 16118] = SR[1, 16118], fra[1, 16117] = HRa[1, 16117]-HLa[2, 16117], fra[1, 16117] = .25*NRa[1, 16117]+.25*NLa[2, 16117], ga[1, 16117] = 0.;

EQ := W[2, 16117]*(-0.3860115660e-1*HRa[2, 16117]-0.1876793978e-1*ga[2, 16117]+0.7836678184e-1) = -2.040147478*10^6*SL[2, 16118]+7.152482840, W[2, 16117]*(-0.3915554290e-1*HRa[2, 16117]-0.1903748329e-1*ga[2, 16117]+0.8260795999e-1) = 3.876387504, W[2, 16117]*(-0.1876794098e-1*HRa[2, 16117]-0.9892449327e-2*ga[2, 16117]+0.3810204607e-1) = -1.983845478*10^6*SL[2, 16118]+5.221405977, HLa[2, 16117] = .9724029753*ga[2, 16117]+HRa[2, 16117], NRa[2, 16117] = 0.7006679273e-1*HRa[2, 16117]-.1803623678*ga[2, 16117]+1.002451672, NLa[2, 16117] = 0.7006679273e-1*HRa[2, 16117]+.2484955248*ga[2, 16117]+1.002451672, SL[3, 16118] = 0.3505865589e-5, fra[2, 16117] = HRa[2, 16117]-HLa[3, 16117];

EQ := W[3, 16117]*(-0.3860115660e-1*HRa[3, 16117]-0.1876793978e-1*ga[3, 16117]+0.7836678184e-1) = -2.040147478*10^6*SL[3, 16118]+10.82168541, W[3, 16117]*(-0.3915554290e-1*HRa[3, 16117]-0.1903748329e-1*ga[3, 16117]+0.8260795999e-1) = 3.876387504, W[3, 16117]*(-0.1876794098e-1*HRa[3, 16117]-0.9892449327e-2*ga[3, 16117]+0.3810204607e-1) = -1.983845478*10^6*SL[3, 16118]+8.751240594, HLa[3, 16117] = .9724029753*ga[3, 16117]+HRa[3, 16117], NRa[3, 16117] = 0.7006679273e-1*HRa[3, 16117]-.1803623678*ga[3, 16117]+1.002451672, NLa[3, 16117] = 0.7006679273e-1*HRa[3, 16117]+.2484955248*ga[3, 16117]+1.002451672, SL[4, 16118] = 0.5304364281e-5, fra[3, 16117] = HRa[3, 16117];

And after these the solving command that I used was:

SOL[j]:=fsolve({seq(EQ[j][n],n=1..N)},indets({entries(EQ[j],nolist)},assignable(name)));

Which returns

SOL[j]:=

As I said, then I tried the solve command:

SOL[j]:=solve({seq(EQ[j][n],n=1..N)},indets({entries(EQ[j],nolist)},assignable(name)));

which returns:

SOL :=

{HLa[1, 16117] = 1.011251860, HLa[2, 16117] = .5007913055, HLa[3, 16117] = -0.4240068535e-1, HRa[1, 16117] = 1.011251860, HRa[2, 16117] = .8728245835, HRa[3, 16117] = .2686716410, NLa[1, 16117] = 1.073306847, NLa[2, 16117] = .9685353734, NLa[3, 16117] = .9417827567, NRa[1, 16117] = 1.073306847, NRa[2, 16117] = 1.132612831, NRa[3, 16117] = 1.078974668, SL[2, 16118] = 0.1737463747e-5, SL[3, 16118] = 0.3505865589e-5, SL[4, 16118] = 0.5304364281e-5, SR[1, 16118] = 0.1737463747e-5, W[1, 16117] = 90.12372195, W[2, 16117] = 69.57451714, W[3, 16117] = 49.58407210, fra[1, 16117] = .5104605550, fra[2, 16117] = .9152252689, fra[3, 16117] = .2686716410, ga[1, 16117] = 0., ga[2, 16117] = -.3825916698, ga[3, 16117] = -.3199006320, v[1, 16118] = 8.447574110*10^(-7)},

{HLa[1, 16117] = 3.043461992, HLa[2, 16117] = 2.386862361, HLa[3, 16117] = -0.4240068535e-1, HRa[1, 16117] = 3.043461992, HRa[2, 16117] = 1.087485894, HRa[3, 16117] = .2686716410, NLa[1, 16117] = 1.215697293, NLa[2, 16117] = 1.410701230, NLa[3, 16117] = .9417827567, NRa[1, 16117] = 1.215697293, NRa[2, 16117] = .8376385519, NRa[3, 16117] = 1.078974668, SL[2, 16118] = 0.2032780481e-5, SL[3, 16118] = 0.3505865589e-5, SL[4, 16118] = 0.5304364281e-5, SR[1, 16118] = 0.2032780481e-5, W[1, 16117] = -106.0268094, W[2, 16117] = 265.7250566, W[3, 16117] = 49.58407210, fra[1, 16117] = .6565996307, fra[2, 16117] = 1.129886580, fra[3, 16117] = .2686716410, ga[1, 16117] = 0., ga[2, 16117] = 1.336253076, ga[3, 16117] = -.3199006320, v[1, 16118] = 9.883410782*10^(-7)}

Thanks in advance for any recommendations and suggestions.

## How to run step by step?...

Maple

Hi,

I want to run an entire worksheet step by step to see errors and how variables are flowing and so on.

I know that I can invoke de debbuger but it doesn't allow me to do so from start.

How can I do that, is that possible?

It´s like:

restart:

<I want to start a step by step from here>
command
command
command
...
...
<and stop here>

## Variable Identification...

Maple

I got a set of ecuations to solve, like this one:

eq:=W[1,0]*(a*HRa[1,0]+b*ga[1,0]+c)=d*SR[1,1]

a,b,c,d are numbers, like 2.0458 and so on.

When I want to solve the set, I need to tell Maple the command solve:

solve( {seq(eq[i],i=1..N)},{variables});  (N is an integer of course)

To set the variables, one must check each equation to write: {W[1,0],HRa[1,0],ga[1,0]...} and so on.

I know that I can use the command is(variable,assignable) to check if a variable has not a value assigned already and, according to true/false I can construct the set {variables} and solve the set of equations.

That´s an easy solution if I need to check variables under a certain pattern, like: X.X,X since I can create a loop and check them one after the other. But my problem is that I have different names for variables or that variables change to assignable from assigned according to other conditions, so I can never be sure if W[1,0] is going to be a variable to compute in all steps instead of SR[1,1].

for example:

if a>3 then
SR[1,1]:=1/2;
else
W[1,0]:=300:
end if;

So, when I need to type solve, the {variables} part is different according to each case. Is there any command that allow me to insert an expression and Maple can return me the variables or parameters in the expression that are not numeric already?

## Simple Plot Issues...

Maple

I was solving thos differential equiation using dsolve:

diff(P(t),t)=b*P(t)+m*t

dsolve({diff(P(t),t)=b*P(t)+m*t,P(t0)=P0});

where t0=2000 and P0=100 and m=9/50

Then, I found b setting at t=2001, P=2*P0=200, I applied fsolve to do this and the result was:

b=-1.5979...

To this point, Maple computes correctly. The problem starts when I tried to plot the result in a single 2D-graph (P vs t) using the computed value for b, the expression involved is:

P(t)=.1126460951*t-0.7049523744e-1-1.090463096*10^1390*exp(-1.597924898*t)

I wrote

plot( .1126460951*t-0.7049523744e-1-1.090463096*10^1390*exp(-1.597924898*t) , t=2000..2001);

The result was a blank plot, only the axes appeared even if I used the y=A..B option in the plot command. Is there a way to get the desired plot without having to evaluate the function at several points and then using this set of points to generate the plot: plot({[a,b],[c,d],[f,g]...})? (that worked, of course).

Thanks and regards.

P.S. I have used Maple for over 15 years now and I've plotted expressions even more complicated than this one, I found this very strange. I guess the 10^1390 has something to do this time, but I'm not sure...