calculate derivative of a function using handle
이전 댓글 표시
Hi, Matlab community
I have two scripts, one is
syms f(x)
f=@(x)func(x);
df=diff(f,x);
fplot(@(x) df(x),[0 10])
the other one is
function f=func(x)
if x >= 1 && x <= 2;
f=-x*1/4+2;
else
f=0;
end
And the error shows like:
Conversion to logical from sym is not possible.
How to solve ths problem?
Thank you for your attention
댓글 수: 2
KSSV
2020년 6월 8일
How did you use those functions...show us the full code.
denial nakayama
2020년 6월 8일
답변 (2개)
Ameer Hamza
2020년 6월 8일
You need to take the derivative of the original function and then apply the limits
syms x
f(x) = (-x*1/4+2);
df(x) = diff(f,x).*(1<=x&x<=2);
fplot(df,[0 10])
댓글 수: 7
denial nakayama
2020년 6월 9일
Ameer Hamza
2020년 6월 9일
Can you paste complete error message?
denial nakayama
2020년 6월 9일
Ameer Hamza
2020년 6월 9일
Try your code again after running
clear f x
denial nakayama
2020년 6월 9일
Ameer Hamza
2020년 6월 9일
Not sure about the issue. I don't have R2014a. Maybe this will work
fplot(matlabFunction(df),[0 10])
Walter Roberson
2020년 6월 9일
In R2014a, fplot() was not yet able to plot symbolic expressions.
Walter Roberson
2020년 6월 8일
function f=func(x)
f = piecewise(x >= 1 && x <= 2, -x*1/4+2, 0);
댓글 수: 3
denial nakayama
2020년 6월 9일
denial nakayama
2020년 6월 9일
Walter Roberson
2020년 6월 9일
function f=func(x)
syms t
temp(t) = feval(symengine, 'piecewise', '([t >= 1 and t <= 2, -t*1/4+2], [Otherwise, 0])');
f = temp(x);
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!