Clear Filters
Clear Filters

To draw an intensity curve with Matlab

1 view (last 30 days)
I have a function :
And I want to draw the intensity curve :
where T has values : 600, 800, 1000, 1100 And λ:(0,10*^-5] I have to use max function with two values and the solution must not consist of repeating four times of similar snippets of code, one for each curve.The image should be stylish. For example. so the texts may not cut curves, but neatly placed just above the maximum point.
Can somebody please help me how I can start ?! I must say I'm a beginner too

Accepted Answer

Star Strider
Star Strider on 16 Feb 2017
Edited: Star Strider on 16 Feb 2017
This should get you started.
Since this seems to be a homework problem, I will let you determine how to locate and plot the peaks. See the documentation for the various functions and the section on Anonymous Functions in Function Basics.
The Code
f = @(L,T) 3.7E-16 ./ (L.^5 .* (exp(0.014 ./ (L .* T)) -1));
T = [600, 800, 1000, 1100];
L = linspace(0, 1E-5);
[Tm,Lm] = meshgrid(T, L);
fm = f(Lm,Tm);
plot(L, fm)
lgndcell = regexp(sprintf('T = %d\n',T), '\n', 'split')
legend(lgndcell(1:end-1), 'Location','NE')
Also see the documentation for the text function. You will need that to label the peaks. Specifically note the name-value pair arguments so you can position the labels correctly with respect to the points you plotted at the peaks.
The Plot
EDIT Added plot my code produces.
Pouyan Msgn
Pouyan Msgn on 17 Feb 2017
Edited: Pouyan Msgn on 17 Feb 2017
I have another question too, why did you use meshgrid ?! I saw the help meshgrid on Matlab but I don't get it.
Star Strider
Star Strider on 17 Feb 2017
My pleasure.
The meshgrid call creates a matching matrix of values for each argument vector. The function then calculates a resulting matrix for both argument matrices, making it easier to calculate and plot them.
The plot function automatically chooses the correct dimension of the ‘fm’ matrix to plot, depending on the x-vector.
The meshgrid call eliminates an explicit loop, although there are likely implicit loops in the way the ‘f’ function is evaluated.
You could also plot the function as:
surfc(Tm, Lm, fm)
grid on
if you want to see what it looks like in 3D.

Sign in to comment.

More Answers (2)

Pouyan Msgn
Pouyan Msgn on 18 Feb 2017
Edited: Pouyan Msgn on 18 Feb 2017
Thank you! I get this after your help and using max function but I don't know how should I use text function to write the value of T for correspond curve....

Pouyan Msgn
Pouyan Msgn on 18 Feb 2017
Edited: Pouyan Msgn on 18 Feb 2017
This how I could develop the code but I fail with one thing !
clear all
F=@(L,T) 3.7415E-16 ./((L.^5).*(exp(0.014 ./(L.*T))-1));
T=[600 800 1000 1100];
[Tm Lm]=meshgrid(T,L);
grid on
[Y I]=max(fm);
hold on
%text(L(I),Y,'T= ')
hold on
for i=1:1:4
S=['T= ',num2str(T(i))]
N = L(I)-1.E-7;
G = Y+5.E8;
text(N,G, S)
I get this image as result :
I see number 6000 everywhere and I don't like it !
Pouyan Msgn
Pouyan Msgn on 20 Feb 2017
OK, for sprintf('T = %4d\n', T), why must we use %4d\n?! what is the philosophy and logic behind that ?! I see if I delete %4d\n and just write sprintf('T = ', T), it gives me just 'T= ' without any number. But why is this so ?!
Star Strider
Star Strider on 21 Feb 2017
You need to specify a format descriptor to tell sprintf to print a numerical value. Your largest temperature values are 4 digits, so I chose '%4d' to output a 4-digit integer for all of them (using leading spaces for the values with less than 4 digits). See the documentation for sprintf for details on specifying format descriptors.
The '\n' is a ‘newline’ character that would normally produce a carriage return and linefeed sequence with, for example, fprintf. Here, I use it as a separator that regexp will recognise as the end-of-string indicator to do the split. See the documentation on regexp for details.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!