Solving nonlinear equation involving sum

1 visualizzazione (ultimi 30 giorni)
Tiku
Tiku il 29 Giu 2021
Commentato: Walter Roberson il 22 Lug 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

Risposte (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 Commento
Walter Roberson
Walter Roberson il 22 Lug 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.

Accedi per commentare.

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by