To draw an intensity curve with Matlab
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Pouyan Msgn
el 16 de Feb. de 2017
Comentada: Star Strider
el 21 de Feb. de 2017
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
0 comentarios
Respuesta aceptada
Star Strider
el 16 de Feb. de 2017
Editada: Star Strider
el 16 de Feb. de 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);
figure(1)
plot(L, fm)
grid
xlabel('\lambda')
ylabel('\itF\rm(\it\lambda,T\rm)')
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.
3 comentarios
Star Strider
el 17 de Feb. de 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:
figure(2)
surfc(Tm, Lm, fm)
grid on
if you want to see what it looks like in 3D.
Más respuestas (2)
Pouyan Msgn
el 18 de Feb. de 2017
Editada: Pouyan Msgn
el 18 de Feb. de 2017
7 comentarios
Star Strider
el 21 de Feb. de 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.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!