Items tagged with fsolve fsolve Tagged Items Feed

Dear All

Please help me for using fsolve

the fsolve command doesnt work!

> restart;
> with(LinearAlgebra); Digits := 20;
print(`output redirected...`); # input placeholder
> Z := Matrix(2); N := 3; y11 := sum(a[n]*x^n, n = 0 .. N); y12 := sum(b[n]*x^n, n = 0 .. N); y21 := sum(c[n]*x^n, n = 0 .. N); y22 := sum(d[n]*x^n, n = 0 .. N); y11 := unapply(y11, x); y12 := unapply(y12, x); y21 := unapply(y21, x); y22 := unapply(y22, x);
print(`output redirected...`); # input placeholder
> A := linalg[matrix](2, 2, [1, -1, 1, exp(x)]); B := linalg[matrix](2, 2, [-3*exp(-x)-1, 2-2*exp(-x), -3*exp(-x)-2, 1-2*cosh(x)]);
print(`output redirected...`); # input placeholder
> C := eval(B, [x = 1]);
print(`output redirected...`); # input placeholder
> Y := linalg[matrix](2, 2, [y11(x), y12(x), y21(x), y22(x)]);
print(`output redirected...`); # input placeholder
> yy11 := diff(y11(x), x); yy12 := diff(y12(x), x); yy21 := diff(y21(x), x); yy22 := diff(y22(x), x); yy11 := unapply(yy11, x); yy12 := unapply(yy12, x); yy21 := unapply(yy21, x); yy22 := unapply(yy22, x);
> YY := linalg[matrix](2, 2, [yy11(x), yy12(x), yy21(x), yy22(x)]);
print(`output redirected...`); # input placeholder
> S := {seq(eval(YY, [x = n/N])-(eval(A, [x = n/N]))*(eval(Y, [x = n/N]))-(eval(B, [x = n/N])) = Matrix(2), n = 1 .. N)};
print(`output redirected...`); # input placeholder
> S1 := {eval(Y, [x = 0]) = linalg[matrix](2, 2, [3, 0, 1, 1])};
print(??); # input placeholder
> SS := `union`(S, S1);
print(??); # input placeholder
> sol := fsolve(SS);

 

Dear All,

I analyzed some example of linear equation systems and tried to distinguish the difference between the solve and fsolve in these cases.

1. In general case, the deviation between solve and fsolve is less than 10^-8, for example:

But, in some case, the deviation is more than 10^-7, for example:

how to reduce the error of solving the problem by fsolve?

2. It seems that solve will automatically translate the answer into numerical result while the system is composed with decimals, for example, we redo the second case with no decimals:

Is it possible to get the exact solution while the decimal is involved in the system?

The related file is attached. I'd appreciate any help on this topic. Thank a lot.

solve_and_fsolve.mw

 

I am trying to solve these equations:

eq1:=cot(theta[n])=(omega[a]^2 - omega[n]^2)/omega[n];

eq2:=cot(theta[n]+ omega[n])=-(omega[b]^2 - omega[n]^2)/omega[n];

for some values of omega[a] and omega[b]. I will in the end create two 3d plots for omega[n] and theta[n] as a funciton of ometga[a] and omega[b]

So for example for some particular values have:

eqs:=subs(omega[a]=0.2, omega[b]=1, [eq1, eq2]);

Then solving,

solve(eqs, [omega[n],theta[n]]);

gives:

I'm however only interested in solutions where omega[n]>=0, but doing this:

solve(eqs, [omega[n],theta[n]], UseAssumptions) assuming omega[n]>=0.0;

returns an empty list. Adding the condition omega[n]>=0.0 to the list of equations also does not work.

Is this a bug or am I missing something? Note, I realize that i can manually go through the entries myself and pick the right solutions, I am just asking how to force maple to do this automagically.

thanks

 

Here is the full code:

restart:

eq1:=cot(theta[n])=(omega[a]^2 - omega[n]^2)/omega[n];

eq2:=cot(theta[n]+ omega[n])=-(omega[b]^2 - omega[n]^2)/omega[n];

eqs:=subs(omega[a]=0.2, omega[b]=1, [eq1, eq2]);

solve(eqs, [omega[n],theta[n]]);

solve(eqs, [omega[n],theta[n]], UseAssumptions) assuming omega[n]>=0.0;

Greetings to all.

At the following Math.Stackexchange Discussion a certain constant was computed in relation to a Master Theorem Type recurrence being solved. This prompted me to try to identify it by the use of the eponymous command. What follows is the content of the Maple session. You may want to read the post in order to get an understanding of what the constant means and how its exact value is calculated.

> fsolve(2/2^a+1/4^a=1, a);
                                   1.271553303

> identify(%);
                                   1.271553303

> identify(%,all);
                                 1/2    1/2
                              2 2      3
                      arcsech(------ + ---- - 1/6 Zeta(5))
                                7       6

> evalf(log[2](1+sqrt(2)));
                                   1.271553303

My questions/observations are:

  • Why does the algorithm fail to spot as simple a constant as the one above or am I just not invoking it correctly?
  • If that last formula were true the author of this code would certainly win a prize for calculating a closed form expression for an odd integer zeta function value! (To be fair here I did notice that the spurious identification disappears when the number of working digits is increased and I do understand that the identification depends critically on the number of digits.)

In concluding I would like to say, why the complicated formula and not the simple one? Let me congratulate you just the same on providing this very useful command. I have worked on pandigital approximations which are slightly related and I understand that adding an operation like the logarithm to an integer base up to some max base value can dramatically increase the search space and may not always be feasible.

Best regards,

Marko Riedel

I want to know which other maple in-built function does the same thing as fsolve and LinearSolve. I can use both to solve systems of equations either by passing the equations directly to fsolve or deciding to generate matrix to be used in LinearSolve while still getting the same result. So, i'm using this medium to ask if there are/is other inbuilt function that does the same/similar thing as the two.

Hello, I am trying to solve 2 equations, and write the solution in a matrix form. How do I do it? This is what i did:

knn:=Matrix(10,1):

for m from 1 to 10 do
P:=fsolve({y=1/kn,y=-tan(kn)},{kn=(m-1)*Pi..m*Pi,y=0..5});
knn[m,1]:=P[1];
end do:

knn[3,1];

Answer is kn=9.317...

How to I get knn[3,1]=9.317...? without the "kn="

I would like to have a matrix of 10x1 with just the values of kn. Thank you.

Using the fsolve commmand how does one solve for just the positive solutions and remove the dublicate values?

Thanks

Hi everyone

I'm currently working on some mandate distribution using "Jefforson's Method" but I have run into some problems.

The general form of the calculations I do is as follows:

d:=fsolve(m = floor(v1/x)+floor(v2/x), x)

But in the case of m=5, v1=4969 and v2=208 it does not work. If I change v1 a bit it works as a charm but when 
4960=<v1=<4969 it does not.

Can any of you figure out why?

 

The equation surely has a solution (well, a lot of solutions). I can figure some out just by estimating and trying. Furthermore, wolfram alpha easily gives me several solutions:

http://www.wolframalpha.com/input/?i=5+%3D+floor%284969%2Fx%29%2Bfloor%28208%2Fx%29

So how come I cannot get Maple to solve it?

 

Thanks in advance!

Hi,

I'm having some difficulty in figureing our how to store the results of an fsolve computation in an indexed variable that I can access subsequently to perform plots and do other calculations.  I have a do loop that, for every increment, has fsolve calculate five variable  (x,y,z.. )from a set of equations that have been entered.  It does the calculations just fine.  What I can't seem to do is set up an array variable (or other indexed variable like a vector) so that with every increment of the loop the values that fsolve generates for x, y, z  ect. can be stored.  That just doesn't seem to work, what am I getting wrong? Any help would be most appreciated.

 

Al Stiegman

Hi,

 

I have a system of equations for which I want to get a solution around an initial guess, unfortunatly I cannot succed it. Here is the system and the initial guess

 

solve({(-(((1/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*((0.005+0.009)*sin(-0.785)+(0.072+1*(Ladssec+Ll))*cos(-0.785)))*((Ladssec*(-id0+(0.953/Lfd)+(0.849/L1d)))+Laqssec*id0)-((1/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*((0.072+1*(Laqssec+Ll))*sin(-0.785)-(0.005+0.009)*cos(-0.785)))*((Laqssec*(-iq0+(0.468/L1q)))+Ladssec*iq0))/(2*2.5))=-1.7858
,(-((((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Ladssec/Lfd))*((Ladssec*(-id0+(0.953/Lfd)+(0.849/L1d)))+Laqssec*id0)-(((0.072+1*(Laqssec+Ll))*Ladssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*Lfd))*((Laqssec*(-iq0+(0.468/L1q)))+Ladssec*iq0)+((Ladssec*iq0)/Lfd)) /(2*2.5))=0.1036
,(-((-((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Ladssec/L1d))*((Ladssec*(-id0+(0.953/Lfd)+(0.849/L1d)))+Laqssec*id0)-(((0.072+1*(Laqssec+Ll))*Ladssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*L1d))*((Laqssec*(-iq0+(0.468/L1q)))+Ladssec*iq0)+((Ladssec*iq0)/L1d)) /(2*2.5))=0.2279
,(-((((0.072+1*(Ladssec+Ll))*Laqssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*L1q))*((Ladssec*(-id0+(0.953/Lfd)+(0.849/L1d)))+Laqssec*id0)-(-((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Laqssec/L1q))*((Laqssec*(-iq0+(0.468/L1q)))+Ladssec*iq0)-((Laqssec*id0)/L1q)) /(2*2.5))=-2.3313

,(-(1*Rfd*((1/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*((0.072+1*(Laqssec+Ll))*sin(-0.785)-(0.005+0.009)*cos(-0.785)))*Ladssec)/(Lfd))=0.0023
,(-(1*Rfd*(1-(Ladssec/Lfd)+((((0.072+1*(Laqssec+Ll))*Ladssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*Lfd)) *Ladssec)))/(Lfd))=-0.0054
,(-(1*Rfd*(-(Ladssec/Lfd)+((((0.072+1*(Laqssec+Ll))*Ladssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*L1d)) *Ladssec)))/(Lfd))= 0.0018
,(-(1*Rfd*(-((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Laqssec/L1q))*Ladssec)/(Lfd))=5.8369e-04

,(-(1*R1d*((1/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*((0.072+1*(Laqssec+Ll))*sin(-0.785)-(0.005+0.009)*cos(-0.785)))*Ladssec)/(L1d))=0.1303
,(-(1*R1d*(-(Ladssec/Lfd)+((((0.072+1*(Laqssec+Ll))*Ladssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*Lfd))*Ladssec)))/(L1d))=0.1157
,(-(1*R1d*(1-(Ladssec/Lfd)+((((0.072+1*(Laqssec+Ll))*Ladssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*L1d)) *Ladssec)))/(L1d))= -0.3192
,(-(1*R1d*(-((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Laqssec/L1q))*Ladssec)/(L1d))=0.0333


,(-(1*R1q*((1/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*((0.005+0.009)*sin(-0.785)+(0.072+1*(Ladssec+Ll))*cos(-0.785))) *Laqssec)/(L1q))=-0.1323
,(-(1*R1q*(((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Ladssec/Lfd))*Laqssec)/(L1q))=-0.0044
,(-(1*R1q*(-((0.005+0.009)/((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll))))*(Ladssec/L1d))*Laqssec)/(L1q))= 0.0051
,(-(1*R1q*(1-(Laqssec/L1q)+((((0.072+1*(Ladssec+Ll))*Laqssec)/(((0.005+0.009)^2+(0.072+1*(Ladssec+Ll))*(0.072+1*(Laqssec+Ll)))*L1q))*Laqssec)))/(L1q))=-0.2349}, {L1d, L1q, Ladssec, Laqssec, Lfd, R1d, R1q, Rfd},useassumptions)

Lfd ~=0.233, R1d~=0.0848, L1d~=0.2, L1q~=-0.09, Ladssec~=0.099, Laqssec~=-0.1, Rfd~=0.00173, R1q~=0.0129

So, newb question here. I've done my best to debug this line of code, but to no avail. For some reason this function is NOT getting solved correcting for the zeros:

cos(L*x) - x*sin(L*x)

 

This is not an extremely complex equation either, so I'm at a loss for why my while loop continues to sit there forever. I've got it set to find N number of zeros, but it'll just keep going forever never finding any zeros. I've tried mixing up the start point, and even changed the range which it's searching for them, but nothing seems to get me any closer. Please help!

 

> restart; with(plots);
> a := 0; b := 1/2; N := 5; w := 1; L := b-a;

Eigenvalue equation
> w := cos(L*x)-sin(L*x)*x;
> plot(w, x = 0 .. 50);

> lam := array(0 .. N+1);

> nn := 0; kk := 5; while nn < N do zz := fsolve(w(x) = 0, x = kk .. kk+1); if type(zz, float) then printf("lam(%d)=%f\n", nn, zz); lam[nn] := zz; nn := nn+1 end if; kk := kk+1 end do

 

Hello,

 

I have the following system of equations to solve which is quite big.. Does anyone know how I can solve it faster or in a more simple way?

Thanks 

solve({(-(1/((0.002+0.001)^2+(0.001+1*(e+p))*(0.001+1*(j+p))))*((0.002+0.001)*sin(-0.39)-(0.001+1*(e+p))*cos(-0.39)*(e*(-m+(0.68/d)+(0.599/g))+j*m)-(1/((0.002+0.001)^2+(0.001+1*(e+p))*(0.001+1*(j+p))))*((0.001+1*(j+p))*sin(-0.39)-(0.002+0.001)*cos(-0.39))*(j*(-n+(0/i)+(-0.73/l))+e*n...

 

Hi,

 

Does anyone know why I cannot solve the following system of equations?

 

solve({(-(0.1e-2+e+p)*j*(e*(-m+.68/d+.599/g)+j*m)/(((0.2e-2+0.1e-2)^2+(0.1e-2+e+p)*(0.1e-2+j+p))*i)+(0.2e-2+0.1e-2)*j*(j*(-n+0*(1/i)-.73/l)+e*n)/(((0.2e-2+0.1e-2)^2+(0.1e-2+e+p)*(0.1e-2+j+p))*i)-j*m/i)/(2*10) = -0.3e-2, (-(0.1e-2+e+p)*j*(e*(-m+.68/d+.599/g)+j*m)/(((0.2e-2+0.1e-2)^2+(0.1e-2+e+p)*(0.1e-2+j+p))*l)+(0.2e-2+0.1e-2)*j*(j*(-n+0*(1/i...

'1.8*a+.4000000000*b+103.9*c-.5000000000*e-102.6*g = 0', '.5000000000*b+102.6*c+.3*d+.3500000000*e-102.1*g = 0', '-.3*a-.3500000000*b+102.1*c+2.5*d-1.450000000*e-102.6*g = 0', '-2.5*a+1.450000000*b+102.6*c+3.3*d+1.050000000*e-102.4*g = 0', '-3.3*a-1.050000000*b+102.4*c+.7*d+.2500000000*e-105.1*g = 0', '-.7*a-.2500000000*b+105.1*c-.2*d+.2000000000*e-105.7*g = 0'

i use solve, it return a = a 

Hi, I cannot solve the 2 implicit functions with 2 unknown (m,n) simultaneously (please see attached maple file). Note: m and n are real numbers.

May I get some advice please? Many thanks.

 

 

 

1 2 3 4 5 6 7 Page 1 of 7