How to plot a single variable function with constraints

조회 수: 11 (최근 30일)
Mihai Giurca
Mihai Giurca 2020년 3월 20일
댓글: Huy Phan Dang 2021년 7월 19일
Hello, I am trying to plot f(x) = 4 - x*sin(x) with constraints x>=6, x<=9 and log(x)>= -1. I tried using meshgrid but the graph came out wrong + it was in the 3rd dimension. Can anyone tell me how I should go about plotting a simple function with these constraints? Thank you!
  댓글 수: 3
Mihai Giurca
Mihai Giurca 2020년 3월 20일
I'm honestly not sure, my professor gave me these constraints and I'm not sure what the log is supposed to mean.
Huy Phan Dang
Huy Phan Dang 2021년 7월 19일
log(x) or lg(x) can mean log 10 of x, my education system alway use lg(x) for log 10 of x as shortcut so it might be what your professor meant

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

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 3월 20일
f = @(x) 4 - x*sin(x);
fplot(f, [6 9]);

Matt J
Matt J 2020년 3월 20일
편집: Matt J 2020년 3월 20일
You can assign NaN to anything you don't want plotted. Example,
x=linspace(0,2,1000);
f=sin(x);
f( 0.5<=x & x<=1)=nan;
plot(x,f);

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by