Solving nonlinear equation involving sum

조회 수: 2 (최근 30일)
Tiku
Tiku 2021년 6월 29일
댓글: Walter Roberson 2021년 7월 22일
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

답변 (1개)

Ildeberto de los Santos Ruiz
Ildeberto de los Santos Ruiz 2021년 7월 21일
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
Walter Roberson
Walter Roberson 2021년 7월 22일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by