How do I plot intersection point of a function and y axis in matlab

5 次查看(过去 30 天)
Sketch the graph of the function y = f(x) and the y-axis onto the same figure. What is the meaning of the point of intersection? Apply the Secant method to solve f(x) = 0 accurate to within 10^(-3) for the equation
A) f(x) = e^x + 2^(-x) + 2 cos(x) ) 6 for 1 x 2.
clc;
clear;
x=[1 2];
y=exp(x)+power(2,(-x))+2*cos(x)-6;
plot(x,y)
%Secant method;
f=@(x) exp(x)+power(2,(-x))+2*cos(x)-6;
x0=1;
x1=2;
epsilon=0.001;
err=abs(x1-x0);
if f(x0)*f(x1)>0
disp('enter valid interval!!!')
else
while err>epsilon
x2=(x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
x0=x1;
x1=x2;
err=abs(x1-x0);
root=x2;
end
fprintf('\n The root is %4.3f ',root)
end
I can solve the secant method part but I can't plot the intersection point of the function and y-axis.
I would appreciate if you can tell me or show me how can I plot?
  1 个评论
Walter Roberson
Walter Roberson 2020-5-23
The interesection point of the function and the y axis is just the point at which the function equals 0. You can plot a marker there or a line such as with xline()

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by