How to solve this equation on MATLAB ? how to get the value of x
1 次查看(过去 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!