help me to find max :((
Afficher commentaires plus anciens
syms x;
f(x) = (2.*x-1).*sin(pi.*x);
xMin = -2; xMax = 1; stepSize = 0.01;
for i=1:5
y=diff(f(x),i);
[val,idx] = max(y) ;%Error using sym/max (line 101)
%Input arguments must be convertible to floating-point numbers.
eval(val)
end
help me fix it plz
2 commentaires
Image Analyst
le 23 Déc 2018
Modifié(e) : Image Analyst
le 23 Déc 2018
You're using a symbolic x but trying to find the max numerically. Don't use syms. Use linspace to define a range for x, then use max(y), not a for loop, to find the first max. What is your desired range for x?\
x = linspace(-15, 15, 1000)
fx = (2.*x-1).*sin(pi.*x);
plot(x, fx, 'b-');
grid on;
xlabel('x', 'FontSize', fontSize);
ylabel('f(x)', 'FontSize', fontSize)

If you want the max of the derivative, why not take the analytical derivative (by the formula) of the function and find the max of that?
Phuc Nguyen Quy
le 23 Déc 2018
Modifié(e) : Phuc Nguyen Quy
le 23 Déc 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!