How to plot a single variable function with constraints
显示 更早的评论
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 个评论
Ameer Hamza
2020-3-20
What does the constraint log(x)>= -1 mean? Does it mean x >= exp(-1)? How does this combine with x>=6, x<=9?
Mihai Giurca
2020-3-20
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
2020-3-20
f = @(x) 4 - x*sin(x);
fplot(f, [6 9]);
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);
类别
在 帮助中心 和 File Exchange 中查找有关 Log Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!