필터 지우기
필터 지우기

My question is what is the value i am getting as the output of my code.

조회 수: 5 (최근 30일)
Varun
Varun 2024년 8월 2일
댓글: Varun 2024년 8월 2일
syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
solve(eqn == 0,x)
the results are given as
  댓글 수: 3
VBBV
VBBV 2024년 8월 2일
@Varun You could alternately use fsolve for the expression and solve it for defined initial value limits. Note that your equation/ function involves a term ((sqrt((1-x.^4)./x.^4))) which can potentially cause the result into a indefinite value. Hence, the initial value need to be more specific to solve this type of equation.
x0 = [0.01 1] % give an initial value excluding 0 !!!
x0 = 1x2
0.0100 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
eqn = @(x) 0.5959 + 0.0321*(x.^2.1)-0.184*(x.^8)+0.0143*(x.^2.5)-0.2359*(sqrt((1-x.^4)./x.^4));
options = optimoptions('fsolve','Display','iter'); % ^
[x] = fsolve(eqn,x0,options)
Norm of First-order Trust-region Iteration Func-count ||f(x)||^2 step optimality radius 0 3 5.56207e+06 1.11e+09 1 1 6 1.09835e+06 0.00500015 1.47e+08 1 2 9 216815 0.0231918 1.93e+07 1 3 12 42764 0.738655 2.54e+06 1 4 15 8428.05 0.771889 3.35e+05 1 5 18 1651.66 0.194943 4.43e+04 1 6 21 320.676 0.20026 5.87e+03 1 7 24 60.9821 0.257676 783 1 8 25 60.9821 1 783 1 9 28 11.0813 0.25 106 0.25 10 31 1.75585 0.116714 14.9 0.25 11 34 0.205127 0.118429 2.17 0.25 12 37 0.0107402 0.0945807 0.294 0.25 13 40 7.55946e-05 0.0365412 0.0207 0.25 14 43 5.37719e-09 0.00365487 0.000172 0.25 15 46 2.81969e-17 3.13519e-05 1.24e-08 0.25 Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
x =
0.6015 - 0.0000i -0.0344 - 1.1446i
real(x)
ans = 1x2
0.6015 -0.0344
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Varun
Varun 2024년 8월 2일
Thank you for your response sir

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

채택된 답변

Arnav
Arnav 2024년 8월 2일
Hi @Varun,
The result that you are getting is a closed form way of representing the solution of the equation. Here root(P(x),x,k) represents the kth root of the symbolic polynomial P(x). You can evaluate these roots numerically using the function vpa as follows:
syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
res = solve(eqn == 0,x);
numeric_res = vpa(res)
The numeric result obtained is:
0.6015191969401057095577237699673
- 0.60342554599494554515246506424316 - 0.0032524435318404812187506975163144i
- 0.60342554599494554515246506424316 + 0.0032524435318404812187506975163144i
- 0.0022957627114584795743384488144413 - 0.6148033016363615664866637134719i
- 0.0022957627114584795743384488144413 + 0.6148033016363615664866637134719i
- 0.034350766702267990632625142341669 - 1.1446441922416124914568634765747i
- 0.034350766702267990632625142341669 + 1.1446441922416124914568634765747i
0.045439493798166588383693273719136 - 1.14543346751870257491869864044i
0.045439493798166588383693273719136 + 1.14543346751870257491869864044i
- 1.1691779737703086214274911464114 - 0.029488409879496751528279391787196i
- 1.1691779737703086214274911464114 + 0.029488409879496751528279391787196i
1.1752945738347608763208400050921 - 0.037263119738081124633951256034582i
1.1752945738347608763208400050921 + 0.037263119738081124633951256034582i
You can refer to the below example for more information:
  댓글 수: 2
Walter Roberson
Walter Roberson 2024년 8월 2일
format long g
syms x
eqn = 0.5959 + 0.0321*(x^2.1)-0.184*(x^8)+0.0143*(x^2.5)-0.2359*(sqrt((1-x^4)/x^4));
F = matlabFunction(eqn)
F = function_handle with value:
@(x)sqrt(-1.0./x.^4.*(x.^4-1.0)).*(-2.359e-1)+x.^(5.0./2.0).*1.43e-2-x.^8.*(2.3e+1./1.25e+2)+x.^(2.1e+1./1.0e+1).*3.21e-2+5.959e-1
numeric_res = fzero(F, [1e-6 1])
numeric_res =
0.601519196940106

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 8월 2일
You are getting garbage values, for a garbage query.
You have used floating point quantities in a symbolic equation. You have used solve() on the equation. solve() is intended to find indefinitely precise solutions. It makes no sense to ask for indefinitely precise solutions to equations involving floating point values, since floating point values are inherently imprecise.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by