Effacer les filtres
Effacer les filtres

Solving nonlinear equation involving sum

2 vues (au cours des 30 derniers jours)
Tiku
Tiku le 29 Juin 2021
Commenté : Walter Roberson le 22 Juil 2021
Hi,
I am trying to solve a nonlinear equation.
Code
syms g y z n
x = 0.0585;
y = 0.01;
Pi = sym(pi);
eqn = 1/g-sqrt(1 + z.^2/((2*n+1)*Pi*y + 4.4*Pi*x*g).^2) == 0;
sol = solve(eqn, g, 'returnconditions', true, 'maxdegree', 4);
G = simplify(sol.g)
My code to solve nonlinear equation
sumArg4 = @ (n,z) 2*pi*(2*n+1)*pi*(G(4)-1)/((2*n+1)*pi + 4.4*pi*x/y)/((2*n+1)*pi + 4.4*pi*x*G(4)/y) + 0.6431;
Here only one out of above four roots satisfies so I took fourth roots (have done those calculation in Mathematica)
mytrial4 = @ (z) symsum(sumArg4 , n, 0, 10000)
%Solving nonlinear equation for z
zsol = fsolve(mytrial4, 2.28)
I read some of the posts where they say fsolve can't be used for symbolic expression.
Running above code gave me an error
function_handle with value:
@(z)symsum(sumArg4,n,0,10000)
Error using fsolve (line 309)
FSOLVE requires all values returned by functions to be of data type double.
Error in solveg_new_gz (line 24)
zsol = fsolve(mytrial4, 2.28)
So could you please suggest me how to take care of this error?
I have done in Mathematica but would like to try in Matlab as well.
Thank you

Réponses (1)

Ildeberto de los Santos Ruiz
It will take you a long time to evaluate the sum from n = 0 to n = 10000.
You can solve it in a short time considering only from n = 0 to n = 10, although it is also necessary to define the equation as a numerical function handle.
% ...
mytrial4 = @(z) double(eval(symsum(sumArg4, n, 0, 10)))
zsol = fsolve(mytrial4, 2.28)
  1 commentaire
Walter Roberson
Walter Roberson le 22 Juil 2021
Do not eval() a symbolic expression. The language of symbolic expressions displayed to the user is not MATLAB and is not MuPad (the internal symbol engine). Use subs() if you must.
In some cases you can use matlabFunction to speed up computation.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by