[Scilab-users] solve a system of equations in scilab

classic Classic list List threaded Threaded
11 messages Options
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] solve a system of equations in scilab

Hello,
How to solve the following system of equations in scilab:
U=(x-2)^2+(y-2)^2-z^2-9;
V=x^6+y^6+z^6-9;

avaluated U and V for z = 0
Gracias





--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab


I am trying to reproduce in Scilab in method of Draghilev. The document is
developed from Maple.
For the previous system develop the following script:

/function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;
Sys(2)=x(1)^6+x(2)^6+z^6-12;
endfunction
z=0;
[j,v,info]=fsolve([2;-0.1],list(Q,z))
disp(j,v,info)
/
   1.

   0.
   1.776D-15

   1.496447
   *0.9574371*

The results do not coincide 100%. The result that differs is highlighted in
black.
The expected result is as follows:
<http://mailinglists.scilab.org/file/t497622/InitialPonit_Dragilev_sMethod.jpg>

It will be possible to graph the function to guide me to select the initial
values.
something like this:

function y = fct1(x)
y = sin(x) - .25*x;
endfunction
fplot2d([-5:.1:5], fct1)
show_window()
x0 = [-5:5];
[x,v,info]=fsolve(x0, fct1);
fplot2d(x', fct1,-1)
disp(x,v)

Gracias
Hermes



















--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

In reply to this post by Hermes
Hello,
 Please I need your comments.
I have tried to solve the system with different initial conditions for
fsolve and I always get the same wrong result for the second variable.

function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;
Sys(2)=x(1)^6+x(2)^6+z^6-12;
endfunction
z=0;
[j,v,info]=fsolve([*1.5;-0.9*],list(Q,z))
disp(j,v,info)

Even when putting these initial values, very similar to the expected values,
fsolve returns
1.496447
0.9574371 the second positive value

By using these values as initial values in this script:

//Draghilev's Method
clear;
function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;
Sys(2)=x(1)^6+x(2)^6+z^6-12;
endfunction
z=0;
[j,v,info]=fsolve([1.5;-0.9],list(Q,z))
disp(j,v,info)

N=100;
smin=0.0;
smax=0.046;
h=0.001;


x01=1.496447;
//3.9691163496*10^-12;
x02=0.9574371;
//0.353580783;
x03=0;
//-1.5130442808;
ics=[x01; x02; x03];

disp(["x(3)^2+(x(2)-2)^2+(x(1)-2)^2-9";"x(3)^6+x(2)^6+x(1)^6-12"],"systema")


disp(["2*(x(1)-2),2*(x(2)-2),2*x(3)";"6*x(1)^5,6*x(2)^5,6*x(3)^5"],"jacobian(Vm,[x(1),x(2),x(3)])");
//

//D1=12*x(2)^5*x(3)-12*(x(2)-2)*x(3)^5;
//D2=12*(x(1)-2)*x(3)^5-12*x(1)^5*x(3);
//DD=12*x(1)^5*(x(2)-2)-12*(x(1)-2)*x(2)^5;
function dydt=odes(t,x)
//dydt=zeros(x);

dydt(1)=-12*x(2)^5*x(3)-12*(x(2)-2)*x(3)^5;
dydt(2)=12*(x(1)-2)*x(3)^5-12*x(1)^5*x(3);
dydt(3)=12*x(1)^5*(x(2)-2)-12*(x(1)-2)*x(2)^5;
endfunction
step=smax/N;
t=[smin:step:smax*N];
t0=0
atol=h/100000;
rtol=h/100000;
LL= ode("rk", ics,t0, t',atol,rtol,odes)
LL=LL'
a=gca();//get the handle of the newly created axes
param3d1(LL(:,3),LL(:,2),LL(:,1),alpha=35,theta=45,"X@Y@Z",flag=[2,2])
a.rotation_angles=[65,75];

The calculations have taken a long time without converging to the solution.
I have interrupted the execution of the same.
By entering the correct values, almost instantaneously, you get the
soclucion of the system.
Help Me!!!
gracias





--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

Hi,

 

The solution returned by fsolve seems to be a valid one because:

-->Q([1.496447;0.9574371 ],0)

ans  =

  - 0.0000002 

  - 0.0000001 

 

You say that the initial guess of [1.5;-0.9] is close to the expected values, however:

-->Q([1.5;-0.9],0)

ans  =

  - 7.54     

  - 0.077934 

is far from being zero. So there is probably a typo in your equations.

 

PS:

Another trivial solution is:

-->Q([-0.9574371,-1.496447],0)

ans  =

  - 0.0000002 

  - 0.0000001 

Such non-linear problems should have multiple solutions, including complex ones.

 

Regards,

Rafael

 

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Hermes
Sent: Sunday, September 17, 2017 8:25 AM
To: [hidden email]
Subject: Re: [Scilab-users] solve a system of equations in scilab

 

Hello,

Please I need your comments.

I have tried to solve the system with different initial conditions for

fsolve and I always get the same wrong result for the second variable.

 

function Sys=Q(x,z)

Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;

Sys(2)=x(1)^6+x(2)^6+z^6-12;

endfunction

z=0;

[j,v,info]=fsolve([*1.5;-0.9*],list(Q,z))

disp(j,v,info)

 

Even when putting these initial values, very similar to the expected values,

fsolve returns

1.496447

0.9574371 the second positive value

 

By using these values as initial values in this script:

 

//Draghilev's Method

clear;

function Sys=Q(x,z)

Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;

Sys(2)=x(1)^6+x(2)^6+z^6-12;

endfunction

z=0;

[j,v,info]=fsolve([1.5;-0.9],list(Q,z))

disp(j,v,info)

 

N=100;

smin=0.0;

smax=0.046;

h=0.001;

 

 

x01=1.496447;

//3.9691163496*10^-12;

x02=0.9574371;

//0.353580783;

x03=0;

//-1.5130442808;

ics=[x01; x02; x03];

 

disp(["x(3)^2+(x(2)-2)^2+(x(1)-2)^2-9";"x(3)^6+x(2)^6+x(1)^6-12"],"systema")

 

 

disp(["2*(x(1)-2),2*(x(2)-2),2*x(3)";"6*x(1)^5,6*x(2)^5,6*x(3)^5"],"jacobian(Vm,[x(1),x(2),x(3)])");

//

 

//D1=12*x(2)^5*x(3)-12*(x(2)-2)*x(3)^5;

//D2=12*(x(1)-2)*x(3)^5-12*x(1)^5*x(3);

//DD=12*x(1)^5*(x(2)-2)-12*(x(1)-2)*x(2)^5;

function dydt=odes(t,x)

//dydt=zeros(x);

 

dydt(1)=-12*x(2)^5*x(3)-12*(x(2)-2)*x(3)^5;

dydt(2)=12*(x(1)-2)*x(3)^5-12*x(1)^5*x(3);

dydt(3)=12*x(1)^5*(x(2)-2)-12*(x(1)-2)*x(2)^5;

endfunction

step=smax/N;

t=[smin:step:smax*N];

t0=0

atol=h/100000;

rtol=h/100000;

LL= ode("rk", ics,t0, t',atol,rtol,odes)

LL=LL'

a=gca();//get the handle of the newly created axes

param3d1(LL(:,3),LL(:,2),LL(:,1),alpha=35,theta=45,"X@Y@Z",flag=[2,2])

a.rotation_angles=[65,75];

 

The calculations have taken a long time without converging to the solution.

I have interrupted the execution of the same.

By entering the correct values, almost instantaneously, you get the

soclucion of the system.

Help Me!!!

gracias

 

 

 

 

 

--

Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html

_______________________________________________

users mailing list

[hidden email]

http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

Hi, Rafael
In my case,
by setting as initial values [1.5, -0.9]
I get:
1.496447
0.9574371
I always get the second positive value, when it is expected to be negative.
clear;
function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;
Sys(2)=x(1)^6+x(2)^6+z^6-12;
endfunction
z=0;

a=[0,0;1,0;1.2,-1;1.5,-0.9]
for i = 1:3
[j,v,info]=fsolve(a(i,:)',list(Q,z))
disp(j,v,"results",a(i,:),"inc;",i)
end

in this script with several initial values, in the last pair of values, the
solution is negative for the two variables, when in fact it is expected:

and to my pairs the results are changed with respect to the variables
/
--> exec('C:\Users\hermesr\Documents\Scilab Xcos\fsolve_eje19.sce', -1)

   1.

 inc;

   0.   0.

 results

   0.
   1.243D-14

  -0.9574371
  -1.496447

   2.

 inc;

   1.   0.

 results

   1.137D-13
   1.345D-11

   1.496447
   0.9574371

   3.

 inc;

   1.2  -1.

 results

   0.
  -1.599D-14/

 * -0.9574371
  -1.496447*





--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

In reply to this post by Rafael Guerra
Hi, Rafael
In my case,
by setting as initial values [1.5, -0.9]
I get:
1.496447
0.9574371
I always get the second positive value, when it is expected to be negative.
clear;
function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;
Sys(2)=x(1)^6+x(2)^6+z^6-12;
endfunction
z=0;

a=[0,0;1,0;1.2,-1;1.5,-0.9]
for i = 1:3
[j,v,info]=fsolve(a(i,:)',list(Q,z))
disp(j,v,"results",a(i,:),"inc;",i)
end

in this script with several initial values, in the last pair of values, the
solution is negative for the two variables, when in fact it is expected:

and to my pairs the results are changed with respect to the variables
/
--> exec('C:\Users\hermesr\Documents\Scilab Xcos\fsolve_eje19.sce', -1)

   1.

 inc;

   0.   0.

 results

   0.
   1.243D-14

  -0.9574371
  -1.496447

   2.

 inc;

   1.   0.

 results

   1.137D-13
   1.345D-11

   1.496447
   0.9574371

   3.

 inc;

   1.2  -1.

 results

   0.
  -1.599D-14/

 * -0.9574371
  -1.496447*


And I do not know why it evaluates the last one for vaslores as 1.2 and -1,
when in the script for a (3, :) is entered [1.5, -0.9]






--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

In reply to this post by Hermes

The “expected” solution is not a solution of the equations you forwarded:

--> Q([1.496447;-0.9574371],0)

ans  =

  - 7.659497  

  - 0.0000001 

 

Therefore there is probably a typo in the Q function forwarded.

 

Plugin-in the fsolve solution into the Q-function does output zeros:

-->Q([1.496447;0.9574371],0)

ans  =

  - 0.0000002 

  - 0.0000001 

 

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Hermes
Sent: Sunday, September 17, 2017 11:52 AM
To: [hidden email]
Subject: Re: [Scilab-users] solve a system of equations in scilab

 

Hi, Rafael

In my case,

by setting as initial values [1.5, -0.9]

I get:

1.496447

0.9574371

I always get the second positive value, when it is expected to be negative.

clear;

function Sys=Q(x,z)

Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;

Sys(2)=x(1)^6+x(2)^6+z^6-12;

endfunction

z=0;

 

a=[0,0;1,0;1.2,-1;1.5,-0.9]

for i = 1:3

[j,v,info]=fsolve(a(i,:)',list(Q,z))

disp(j,v,"results",a(i,:),"inc;",i)

end

 

in this script with several initial values, in the last pair of values, the

solution is negative for the two variables, when in fact it is expected:

 

and to my pairs the results are changed with respect to the variables

/

--> exec('C:\Users\hermesr\Documents\Scilab Xcos\fsolve_eje19.sce', -1)

 

   1.

 

inc;

 

   0.   0.

 

results

 

  0.

   1.243D-14

 

  -0.9574371

  -1.496447

 

   2.

 

inc;

 

   1.   0.

 

results

 

   1.137D-13

   1.345D-11

 

   1.496447

   0.9574371

 

   3.

 

inc;

 

   1.2  -1.

 

results

 

   0.

  -1.599D-14/

 

* -0.9574371

  -1.496447*


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

I've tried migrating the Maple code to Scilab:

<http://mailinglists.scilab.org/file/t497622/from_Maple_fsolve.jpg>

And this is how I do it:
clear;
function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;
Sys(2)=x(1)^6+x(2)^6+z^6-12;
endfunction
z=0;
[j,v,info]=fsolve([1.5;-0.9],list(Q,z))
disp(j,v,info)

is there a better way for Scilab?
I would like to get the three result [x1 x2 x3] with x3 = 0.
I am venturing into Scilab for the first time. My experience, not much, is
in Maple!
GRACIAS



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

Schlumberger-Private

As suspected you have an obvious typo in your equations, there is a plus that should be a minus:

 

Sys(1)=(x(1)-2)^2+(x(2) - 2)^2+z^2-9;

 

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Hermes
Sent: Sunday, September 17, 2017 12:56 PM
To: [hidden email]
Subject: Re: [Scilab-users] solve a system of equations in scilab

 

I've tried migrating the Maple code to Scilab:

 

<http://mailinglists.scilab.org/file/t497622/from_Maple_fsolve.jpg>

 

And this is how I do it:

clear;

function Sys=Q(x,z)

Sys(1)=(x(1)-2)^2+(x(2)+2)^2+z^2-9;

Sys(2)=x(1)^6+x(2)^6+z^6-12;

endfunction

z=0;

[j,v,info]=fsolve([1.5;-0.9],list(Q,z))

disp(j,v,info)

 

is there a better way for Scilab?

I would like to get the three result [x1 x2 x3] with x3 = 0.

I am venturing into Scilab for the first time. My experience, not much, is

in Maple!

GRACIAS

 

 

 

--

Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html

_______________________________________________

users mailing list

[hidden email]

http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab

Thank you Rafael, a million thanks. I had not noticed that mistake, now
everything is correct,

xec('C:\Users\hermesr\Documents\Scilab Xcos\fsolve_eje19.sce', -1)

   1.

 inc;

   0.   0.

 results

   0.
   3.553D-15

   1.496447
  -0.9574371

   2.

 inc;

   1.   0.

 results

   1.137D-13
   1.345D-11

   1.496447
  -0.9574371

   3.

 inc;

   1.2  -1.

 results

   0.
   3.553D-15

   1.496447
  -0.9574371

   4.

 inc;

   1.5  -0.9

 results

   0.
   3.553D-15

   1.496447
  -0.9574371
 GRACIAS




--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hermes Hermes
Reply | Threaded
Open this post in threaded view
|

Re: solve a system of equations in scilab


with this script I manage to evaluate and obtain the third value within the
results vector.

clear;
function Sys=Q(x,z)
Sys(1)=(x(1)-2)^2+(x(2)-2)^2+x(3)^2-9;
Sys(2)=x(1)^6+x(2)^6+x(3)^6-12;
Sys(3)=x(3);
endfunction


a=[0,0 0;1 0 0;1.2 -1 0;1.5 -0.9 0]
for i = 1:4
x(3)=0.0;
[j,v,info]=fsolve(a(i,:)',list(Q,x(3)))
disp(j',"estimated zero",v',"value of function at x","results",
a(i,:),"iinitial value:",i)
end
--> exec('C:\Users\hermesr\Documents\Scilab Xcos\fsolve_eje20.sce', -1)

   1.

 iinitial value:

   0.   0.   0.

 results

 value of function at x

   0.   3.553D-15   0.

 estimated zero

   1.496447  -0.9574371   0.

   2.

 iinitial value:

   1.   0.   0.

 results

 value of function at x

   1.137D-13   1.345D-11   0.

 estimated zero

   1.496447  -0.9574371   0.

   3.

 iinitial value:

   1.2  -1.   0.

 results

 value of function at x

   0.   3.553D-15   0.

 estimated zero

   1.496447  -0.9574371   0.

   4.

 iinitial value:

   1.5  -0.9   0.

 results

 value of function at x

   0.   3.553D-15   0.

 estimated zero

   1.496447  -0.9574371   0.




--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users