How to plot a linear approximation next to a function?
显示 更早的评论
Hey,
I have a function
f=@(x)0.5*(x-2).^2-2*cos(2*x)-1.5;
And I want next to the function f(x) to plot:
f(-1)+f'(-1)(x-(-1))
where f'(x)=x+4sin(2x)-2
How do I go about this?
I tried making a function file
function y=linjar(a)
a=-1;
f(a)=0.5*(a-2).^2-2*cos(2*a)-1.5
dy(a)=a+4*sin(2*a)-2;
y=f(a)+dy(a)*(x-a);
and then calling the function out on another script with
f=@(x)0.5*(x-2).^2-2*cos(2*x)-1.5;
x=linspace(-3,7);
plot(x,f(x))
axis([-3 7 -5 10]), grid on
hold on
plot(a,linjar(a,-1))
and I get the message: Error using linjar Too many input arguments.
I'm new to Matlab so ANY ideas where to start are welcomed.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!