Area fill under a curve

조회 수: 18 (최근 30일)
basim almutairi
basim almutairi 2021년 9월 6일
답변: Star Strider 2021년 9월 6일
Greetings all,
I created a code to plot the function w = x*e^x*cos(x) in the domin (0.2pi). I have to create two plots. one by using the function fplot, and then another graph with fill in under the curve. my code is as follow:
w = @(x) x.*exp(-x).*cos(x) , [0,2*pi];
fplot(w , [0,2*pi])
figure
area(w)
what is wrong here?
regards

답변 (2개)

Simon Chan
Simon Chan 2021년 9월 6일
Check the MATLAB documentation about area.
w is a function handle and it is not supported.
Try the following:
x=linspace(0,2*pi,100);
y=x.*exp(-x).*cos(x);
figure
area(x,y)

Star Strider
Star Strider 2021년 9월 6일
For the fill plot, use the data that fplot has already created —
w = @(x) x.*exp(-x).*cos(x);
hfp = fplot(w , [0,2*pi]); % Return Object Handle
figure
area(hfp.XData, hfp.YData) % Access Properties
.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by