Plotting a function and a horizontal line segment

조회 수: 8 (최근 30일)
Andy Parsons
Andy Parsons 2017년 8월 15일
댓글: Star Strider 2017년 8월 16일
I need to plot f(x) = -ln(x+0.01)+e^x and g(x)=f(0) from x=0 to the second intercept point. I can plot the f(x) function, I just don't know how to plot both of them together (and how I plot a horizontal line segment). Thanks
  댓글 수: 3
Andy Parsons
Andy Parsons 2017년 8월 16일
are you able to elaborate on this? thanks
Star Strider
Star Strider 2017년 8월 16일
See my Answer.

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

답변 (1개)

Star Strider
Star Strider 2017년 8월 15일
Try this:
f = @(x) exp(x) - log(x+0.01);
x2nd = fzero(@(x) f(x)-f(0), 5); % Find Second ‘x’ At ‘f(0)’
x = linspace(0, 2);
y = f(x);
figure(1)
plot(x, y)
hold on
plot([0 x2nd], f(0)*[1 1], '-r')
hold off
grid

카테고리

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