If i try to write derivative of f in the below code(i pointed here), it doesn't work. why?

조회 수: 4 (최근 30일)
clear on
clc
syms x
x1=2.5;
f=@(x) x*sqrt(x)+2*x^3+1.5;
df=@(x)(3/2)*sqrt(x)+6*x^2; %[here]
f1= f(x1)+df(x1)*(x-x1);
figure(1)
fplot(f,[0 5])
hold on
fplot(f1,[0 5])
grid on

답변 (1개)

Birdman
Birdman 2020년 3월 30일
You do not have to use Symbolic approach this time. Try the following code:
hold off;
x1=2.5;
f=@(x) x.*sqrt(x)+2*x.^3+1.5; %f(x)
Df=@(x) 6.*x.^2+1.5.*sqrt(x); %derivative of f(x)
f1=@(x) f(x1)+Df(x1)*(x-x1);
fplot(f,[0 5]);hold on;fplot(f1,[0 5]);grid on;
  댓글 수: 2
Shaik Merkatur Hakim Marjuban
Shaik Merkatur Hakim Marjuban 2020년 3월 30일
clear on
clc
syms x
x1=2.5;
f=@(x) x*sqrt(x)+2*x^3+1.5;
df=@(x)diff(f,x); %[here]
f1= f(x1)+df(x1)*(x-x1);
figure(1)
fplot(f,[0 5])
hold on
fplot(f1,[0 5])
grid on
Why didn’this work?
Birdman
Birdman 2020년 3월 30일
Firstly, get rid of the
syms x
line because after that line, you use numerical evaluation to get the result. Secondly, you have to define f1 as a function but instead, you define it as if it was a constant value. That is why it is not working. So, use my code to get the result.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by