Problem in putting limit to the variable

2 vues (au cours des 30 derniers jours)
Ipshita
Ipshita le 27 Nov 2020
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

Réponses (1)

Ameer Hamza
Ameer Hamza le 27 Nov 2020
'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]);

Community Treasure Hunt

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

Start Hunting!

Translated by