MATLAB: Trying to fill the area under the function up to the dotted line…. can’t figure out how to get area or fill functions to work

areafillMATLAB

clear;clc;
syms lam
c1=3.7142*10^-16; %W*m^2 c2=1.4388*10^-2; %m*K eps=0.7; T=2000; %K c=299792458; %m/s h=6.62607004*10^-34; %m^2*kg/s E1=1.1*1.602*10^-19; %J or kg*m^2/s^2
lam1=h*c/E1;
M=eps*c1/(lam.^5*(exp(c2/(lam*T))-1)); fplot(M,[0,10*10^-6]) line([lam1 lam1],[0 M1],'Color','red','LineStyle','–')
x=linspace(0,lam1); M1=eps*c1/(lam1^5*(exp(c2/(lam1*T))-1)); area(x,M1)

Best Answer

Hi,
i suppose you wanted to achieve this:
to do so i changed your code this way:
clear;
clc;
syms lam
c1=3.7142*10^-16; %W*m^2
c2=1.4388*10^-2; %m*K
eps=0.7;
T=2000; %K
c=299792458; %m/s
h=6.62607004*10^-34; %m^2*kg/s
E1=1.1*1.602*10^-19; %J or kg*m^2/s^2
lam1=h*c/E1;
x=linspace(0,lam1);
M=eps*c1/(lam.^5*(exp(c2/(lam*T))-1));
M1=eps*c1./(x.^5.*(exp(c2./(x*T))-1));
hold on
fplot(M,[0,10*10^-6])
line(x, M1,'Color','red','LineStyle','--')
area(x,M1)
hold off
Best regards
Stephan