To draw an intensity curve with Matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2017년 2월 16일
편집: Star Strider
2017년 2월 16일
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
Star Strider
2017년 2월 17일
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.
추가 답변 (2개)
Pouyan Msgn
2017년 2월 18일
편집: Pouyan Msgn
2017년 2월 18일
댓글 수: 7
Star Strider
2017년 2월 21일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!