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
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)
0000 Screenshot.png
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
Phuc Nguyen Quy le 23 Déc 2018
Modifié(e) : Phuc Nguyen Quy le 23 Déc 2018
assume(x, 'Real');
I just want to find max of every diff(f,i) with i=1->5
if this way not to good can u tell me another way?
thank you <3

Connectez-vous pour commenter.

 Réponse acceptée

Stephan
Stephan le 23 Déc 2018
Modifié(e) : Stephan le 23 Déc 2018

0 votes

Hi,
two steps. Symbolic finding the derivatives and then calculate numeric over the functions you got.
syms x y;
f(x) = (2.*x-1).*sin(pi.*x);
for i=1:5
y(i)=diff(f(x),i);
end
fun=matlabFunction(y');
x=-2:0.01:1;
result=fun(x);
maxres = max(result,[],2)
Best regards
Stephan

3 commentaires

Walter Roberson
Walter Roberson le 23 Déc 2018
? Is the question to find which of the first 5 derivatives and which location in range x together lead to the maximum value?? Or the maximum over a given range of x for each of the first 5 derivatives? Or the global maximum for each of the first 5 derivatives?
Phuc Nguyen Quy
Phuc Nguyen Quy le 23 Déc 2018
thank you so much <3
Walter Roberson
Walter Roberson le 23 Déc 2018
For that function, the global maxima for each of the derivatives can be fairly far outside the range -2 to +1. Indeed, it is not difficult to show that the 4th derivative (for example) has local maxima that increase without bound towards +/- infinity.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by