Solving nonlinear equation involving sum
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)
Above gives me four root as suggested in https://www.mathworks.com/matlabcentral/answers/829308-solutions-are-only-valid-under-certain-conditions?s_tid=prof_contriblnk by Walter Robertson.
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
0 Kommentare
Antworten (1)
Ildeberto de los Santos Ruiz
am 21 Jul. 2021
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 Kommentar
Walter Roberson
am 22 Jul. 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.
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!