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 Kommentare

Image Analyst
Image Analyst am 23 Dez. 2018
Bearbeitet: Image Analyst am 23 Dez. 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 am 23 Dez. 2018
Bearbeitet: Phuc Nguyen Quy am 23 Dez. 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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephan
Stephan am 23 Dez. 2018
Bearbeitet: Stephan am 23 Dez. 2018

0 Stimmen

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 Kommentare

Walter Roberson
Walter Roberson am 23 Dez. 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 am 23 Dez. 2018
thank you so much <3
Walter Roberson
Walter Roberson am 23 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by