Problem in putting limit to the variable

2 次查看(过去 30 天)
I want to find the maximum value of f for x between 0 and 0.9. Please tell how can I put the limit to x in this code.
syms x
0<x & x<0.9;
f=0.3*(x-0.6)*(x-0.9)-0.9*cos(0.6)*x*(x-0.9)+0.6*cos(0.9)*x*(x-0.6)-cos(x);
f2 = diff(f,x)==0;
extreme_points = vpasolve(f2==0,x);
extreme_values = subs(f, x, extreme_points);
extreme_values

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-11-27
'x' is already in this range. You are printing the value of 'extreme_values', not 'extreme_points'
syms x
f=0.3*(x-0.6)*(x-0.9)-0.9*cos(0.6)*x*(x-0.9)+0.6*cos(0.9)*x*(x-0.6)-cos(x);
f2 = diff(f,x)==0;
extreme_points = vpasolve(f2==0,x);
extreme_values = subs(f, x, extreme_points);
Result
>> extreme_points
extreme_points =
0.0061113661628718004024766518326605 % greater than 0
>> extreme_values
extreme_values =
-0.83801606593057221627803628819248
In general, you can specify the range in vpasolve like this
extreme_points = vpasolve(f2==0,x, [0 0.9]);

类别

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