Hello,
I need to solve a non-linear equation with an eliptic integral in it. I tried to used fsolve but it don't want to work, any ideas. I copy the code below:
NI = 6.749914199660242e+05;
NI_ol = 1.749914199660242e+05;
Muo = 4*pi*10^-7; % (T*m/A)
a = 0.2073;
y = 0.15;
% Bos_c = Muo*(NI-NI_ol)*(a^2)/((z(1)^2 + a^2)^(1.5));
% m = (4*a*y)/((a+y)^2+z(1)^2);
%
% [K, E]= ellipke(m);
% Be = 2*Muo*NI*a*((2*m)^0.5)*(a*m*E/(2-2*m) + y*K - y*(2-m)*E/(2-2*m))/(2*pi*(2*a*y)^(1.5));
F=@(z) [Muo*(NI-NI_ol)*(a^2)/((z(1)^2 + a^2)^(1.5))...
- 2*Muo*NI*a*((2*m)^0.5)*(a*m*E/(2-2*m) + y*K - y*(2-m)*E/(2-2*m))/(2*pi*(2*a*y)^(1.5));...
m - (4*a*y)/((a+y)^2+z(1)^2);
[K, E]== ellipke(m)];
z_c = [0; 1000];
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
neff = fsolve(F,z_c,opts);

 Réponse acceptée

Matt J
Matt J le 17 Mar 2020
Modifié(e) : Matt J le 17 Mar 2020
It does not make sense to have a relational expression like,
[K, E]== ellipke(m)
as one of your equations, expecially one that doesn't depend on any of your unknowns, z(i). Also, z(2) is not used anywhere in the system of equations. In other words, you have multiple equations in a single unknown z(1), so the system is not likely to have a solution.

6 commentaires

carlos Hernando
carlos Hernando le 17 Mar 2020
Modifié(e) : carlos Hernando le 17 Mar 2020
Thank you for your answer Matt. Yes I realize that, I rewrite the code and now it looks like this:
NI = 6.749914199660242e+05;
NI_ol = 1.749914199660242e+05;
Muo = 4*pi*10^-7; % (T*m/A)
a = 0.2073;
y = 0.15;
% Bos_c = Muo*(NI-NI_ol)*(a^2)/((z(1)^2 + a^2)^(1.5));
% m = (4*a*y)/((a+y)^2+z(1)^2);
%
% [K, E]= ellipke(m);
% Be = 2*Muo*NI*a*((2*m)^0.5)*(a*m*E/(2-2*m) + y*K - y*(2-m)*E/(2-2*m))/(2*pi*(2*a*y)^(1.5));
m = [0;1];
K = [0;1000];
E = [0;1000];
F=@(z) [Muo*(NI-NI_ol)*(a^2)/((z(1)^2 + a^2)^(1.5))...
- 2.*Muo.*NI.*a.*((2.*m).^0.5).*(a.*m.*E./(2-2.*m) + y.*K - y.*(2-m).*E./(2-2.*m))./(2*pi*(2*a*y)^(1.5));
m - (4*a*y)/((a+y)^2+z(1)^2);
K - ellipticK(m);
E - ellipticE(m)];
z_c = [0; 10000];
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
fsolve(F,z_c,opts);
But I am unable to get a solution. Yes there is only one unknown z, the first equation is the only one that matters, but inside there are the parameters m, K and E. This is why I need to transform the system to a 4 equation system
Matt J
Matt J le 17 Mar 2020
Modifié(e) : Matt J le 17 Mar 2020
Yes there is only one unknown z,
If you only have 1 unknown, your initial guess z_c should be a scalar, not a length 2 vector.
the first equation is the only one that matters, but inside there are the parameters m, K and E. This is why I need to transform the system to a 4 equation system
if m, K, and E are unknowns, they should be part of your unknown vector, z, so that F(z) will depend on them. Also, these lines have no purpose, if m, K, and E are variables you are trying to solve for:
m = [0;1];
K = [0;1000];
E = [0;1000];
Ok understood, I rewrite the code, but do I have to declare z in any special way?
I get the following error: Index exceeds the number of array elements (1).
NI = 6.749914199660242e+05;
NI_ol = 1.749914199660242e+05;
Muo = 4*pi*10^-7; % (T*m/A)
a = 0.2073;
y = 0.15;
F=@(z) [Muo*(NI-NI_ol)*(a^2)/((z(1)^2 + a^2)^(1.5))...
- 2*Muo*NI*a*((2*z(2))^0.5)*(a*z(2)*z(4)/(2-2*z(2)) - y*z(3) + ...
y*(2-z(2))*z(4)/(2-2*z(2)))/(2*pi*(2*a*y)^(1.5));
z(2) - (4*a*y)/((a+y)^2+z(1)^2);
z(3) - ellipticK(z(2));
z(4) - ellipticE(z(2))];
z_c = 2;
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
fsolve(F,z_c,opts);
Matt J
Matt J le 17 Mar 2020
Modifié(e) : Matt J le 17 Mar 2020
z_c must be the same length as the number of unknowns that you have. It appears from the rewritten code that you now have 4 unknowns. Therefore, zc must be of length 4.
However, these 2 equations look like they can be eliminated
z(3) - ellipticK(z(2));
z(4) - ellipticE(z(2))];
because once you solve for z(1) and z(2) from the first two equations, the values of z(3) and z(4) follow trivially. If you eliminate z(3) and z(4) from the problem, then you will have 2 unknowns and z_c will have to be of length 2.
Thank you Matt, unknowns z(3) and z(4) are inside equation 1, I cannot eliminated them. The code now looks like this:
NI = 6.749914199660242e+05;
NI_ol = 1.749914199660242e+05;
Muo = 4*pi*10^-7; % (T*m/A)
a = 0.2073;
y = 0.15;
F=@(z) [Muo*(NI-NI_ol)*(a^2)/((z(1)^2 + a^2)^(1.5))...
- 2*Muo*NI*a*((2*z(2))^0.5)*(a*z(2)*z(4)/(2-2*z(2)) - y*z(3) + ...
y*(2-z(2))*z(4)/(2-2*z(2)))/(2*pi*(2*a*y)^(1.5));
z(2) - (4*a*y)/((a+y)^2+z(1)^2);
z(3) - ellipticK(z(2));
z(4) - ellipticE(z(2))];
z_c = [2 0.5 1 1] ;
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
fsolve(F,z_c,opts);
It seems to work, but is unable to find a solution, the following message appears:
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 8.000000e+02.
Any idea how can I solve this?
carlos Hernando
carlos Hernando le 17 Mar 2020
Ok I sort it out, just eliminating opts seems to work.
Thank you Matt

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by