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 Comments

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?
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

Sign in to comment.

 Accepted Answer

Stephan
Stephan on 23 Dec 2018
Edited: Stephan on 23 Dec 2018
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 Comments

? 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?
thank you so much <3
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.

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!