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 件のコメント

Image Analyst
Image Analyst 2018 年 12 月 23 日
編集済み: Image Analyst 2018 年 12 月 23 日
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 2018 年 12 月 23 日
編集済み: Phuc Nguyen Quy 2018 年 12 月 23 日
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

サインインしてコメントする。

 採用された回答

Stephan
Stephan 2018 年 12 月 23 日
編集済み: Stephan 2018 年 12 月 23 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2018 年 12 月 23 日
? 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 2018 年 12 月 23 日
thank you so much <3
Walter Roberson
Walter Roberson 2018 年 12 月 23 日
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.

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by