How to solve this equation on MATLAB ? how to get the value of x
조회 수: 3 (최근 30일)
이전 댓글 표시
((30\((0.45+0.1233*x)*(12+0.2958*x)))-(2.41*((0.57-0.11789*x)^(-0.77))=0)
HOW TO FIND THE VALUE OF X FOR WHICH THE WHOLE EQUATION BECOMES 0
댓글 수: 0
답변 (2개)
Ameer Hamza
2020년 9월 25일
편집: Ameer Hamza
2020년 9월 25일
You can use fsolve()
f = @(x) (30\((0.45+0.1233*x)*(12+0.2958*x)))-(2.41*((0.57-0.11789*x)^(-0.77)));
x_sol = fsolve(f, rand())
Result
>> x_sol = fsolve(f, rand())
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.
<stopping criteria details>
x_sol =
-50.5386
댓글 수: 2
Ameer Hamza
2020년 9월 28일
편집: Ameer Hamza
2020년 9월 28일
The value is very close to zero
>> f(x_sol)
ans =
6.7308e-11
This is 0.000000000067308. You cannot get exactly zero using numerical methods and finite-precision mathematics.
You can get more closer to zero by using a tighter optimality tolerance
f = @(x) (30\((0.45+0.1233*x)*(12+0.2958*x)))-(2.41*((0.57-0.11789*x)^(-0.77)));
opts = optimoptions('fsolve', 'OptimalityTolerance', 1e-16);
x_sol = fsolve(f, rand(), opts);
Result
>> f(x_sol)
ans =
-2.2204e-16
Star Strider
2020년 9월 25일
Running vpasolve two times reveals two solutions:
syms x
f = ((30\((0.45+0.1233*x).*(12+0.2958*x)))-(2.41*((0.57-0.11789*x).^-0.77)));
[xs] = vpasolve(f, 'random',1)
producing:
xs =
-50.538642583200665582981460055213
xs =
8.0085634626306504965321046489768 - 17.862103670822392773324688261794i
.
댓글 수: 2
Star Strider
2020년 9월 28일
It is correct, within floating-point approximation error, that is as accurate as it is possible to get using IEEE 754 floating-point operations and 64-bit precision:
syms x f(x)
f(x) = ((30\((0.45+0.1233*x).*(12+0.2958*x)))-(2.41*((0.57-0.11789*x).^-0.77)))
x1 = -50.538642583200665582981460055213;
fx1 = vpa(f(x1))
fx1 = double(fx1)
x2 = 8.0085634626306504965321046489768 - 17.862103670822392773324688261794i;
fx2 = vpa(f(x2))
fx2 = double(fx2)
produces:
fx1 =
-0.00000000000000025499106397930409767855524521741
fx1 =
-2.549910639793041e-16
fx2 =
0.000000000000000043859674162247215336179795855927 + 0.000000000000000012914849938348163810324610654156i
fx2 =
4.385967416224722e-17 + 1.291484993834816e-17i
eps_value = eps
produces:
eps_value =
2.220446049250313e-16
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!