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

질문:

2018년 12월 23일

댓글:

2018년 12월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by