Matlab Homework: Plotting T vs λ with Max Function and Stylish Design

  • Thread starter Thread starter Pouyan
  • Start date Start date
  • Tags Tags
    Matlab Plotting
Click For Summary
SUMMARY

The discussion focuses on plotting temperature (T) against wavelength (λ) using MATLAB, specifically employing the max function to enhance the visual representation of the data. The user implements a function F to calculate values based on given T values (600, 800, 1000, 1100) and a range for λ (0 to 10^-5). The solution emphasizes avoiding repetitive code snippets for each curve and ensuring that text annotations are placed neatly above the maximum points on the plot. The final code successfully plots the curves and annotates them with the corresponding T values.

PREREQUISITES
  • MATLAB programming skills
  • Understanding of function handles in MATLAB
  • Familiarity with meshgrid for 2D data representation
  • Knowledge of plotting functions and text annotations in MATLAB
NEXT STEPS
  • Explore MATLAB's advanced plotting techniques for enhanced visualizations
  • Learn about MATLAB's text function for dynamic annotations in plots
  • Investigate the use of vectorization to optimize MATLAB code performance
  • Study the principles of data visualization to improve plot aesthetics
USEFUL FOR

Students and professionals in engineering and scientific fields who are using MATLAB for data visualization, particularly those working on thermal radiation problems or similar computational tasks.

Pouyan
Messages
103
Reaction score
8

Homework Statement



I have a function :
latex1.gif

and I want to draw :
intensity.png

Homework Equations



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.

The Attempt at a Solution


[/B]
This is the way how I start :
F=@(L,T) 3.7415E-16 ./((L.^5).*(exp(0.014 ./(L.*T))-1));
T=[600, 800, 1000, 1100];
L=0:10^-6:10^-5;
[Lm Tm]=meshgrid(L,T);
fm=F(Lm,Tm);
plot(L,fm)
hold on
grid on
[Y I]=max(fm);
plot(L(I),Y,'*')
And I get :
https://se.mathworks.com/matlabcentral/answers/uploaded_files/70252/image1.bmp
My question is how should I use text function in Matlab to write T for correspond curve
 
Physics news on Phys.org
This how I could develop the code but I fail with one thing !

clear all

clc

F=@(L,T) 3.7415E-16 ./((L.^5).*(exp(0.014 ./(L.*T))-1));

T=[600 800 1000 1100];

L=0:10^-7:10^-5;

[Tm Lm]=meshgrid(T,L);

fm=F(Lm,Tm);

plot(L,fm)

grid on

[Y I]=max(fm);

hold on

plot(L(I),Y,'*')

%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)
end

I get this image as result :

https://se.mathworks.com/matlabcentral/answers/uploaded_files/70256/image2.bmp
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
6K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K