Error in defined expression for Fresnel equation in matlab ( please )?

In summary: I just told you how to make one.1. Open Notepad.2. Copy the code from the website you gave into Notepad.3. Save the Notepad file as "fresnelplot.m" in your MATLAB working directory.4. Use the code in your MATLAB program as described above.
  • #1
error 401
19
0
error in defined expression for Fresnel equation in MATLAB (urgent please )??

hi

i have code for plotting Fresnel equation but there's something i didn't understand it and gives
error >>(((

plotopt - plotting option (type 'R' for plotting reflectivity,
% 'A' for absorptivity or 'RA' for both)

))))

any body can explain what should i do .. and how can i define (plotopt ) ? thanks in advance !

the total code ((


thetadeg = (0:0.1:90);
theta = thetadeg*pi/180;

[a,b,c] = intrc(n1,n2,k2,theta);

if nargin<4 || isempty(plotopt)
fprintf('No plotting option specified. Type \''help fresnelplot\'' for further details.\n');
return;
end;
if nargin==4
if ischar(plotopt)
switch plotopt
case {'R','r'}
plot(thetadeg,a,thetadeg,b,thetadeg,c)
legend('Rs','Rp','R','Location','northwest');
xlabel('Angle of incidence \theta');
ylabel('Reflectivity');
case {'A','a'}
plot(thetadeg,1-a,thetadeg,1-b,thetadeg,1-c)
legend('As','Ap','A','Location','northwest');
xlabel('Angle of incidence \theta');
ylabel('Absorptivity');
case {'RA','ra','AR','ar'}
subplot(2,1,1)
plot(thetadeg,a,thetadeg,b,thetadeg,c)
legend('Rs','Rp','R','Location','northwest');
xlabel('Angle of incidence \theta');
ylabel('Reflectivity');
subplot(2,1,2)
plot(thetadeg,1-a,thetadeg,1-b,thetadeg,1-c)
legend('As','Ap','A','Location','northwest');
xlabel('Angle of incidence \theta');
ylabel('Absorptivity');
otherwise
fprintf('%s is not a valid option. Type \''help fresnelplot\'' for further details.\n',plotopt);
end;
else fprintf('Option must be a string. Type \''help fresnelplot\'' for further details.\n');
end;
end;
))
 
Physics news on Phys.org
  • #2


It looks to me like the above is the body of a function with parameters for plotopt and nargin.

Your code is using these values without ever having set them to known values.
 
  • #3


i am using MATLAB 2009 . and gives the error (( ? Undefined function or variable 'plotopt'.))...
 
  • #4


Mark44 said:
It looks to me like the above is the body of a function with parameters for plotopt and nargin.

Your code is using these values without ever having set them to known values.

error 401 said:
i am using MATLAB 2009 . and gives the error (( ? Undefined function or variable 'plotopt'.))...
That's what I'm saying. The code you show refers to plotopt (and nargin) and MATLAB doesn't know what these are.

In post 1, you wrote "the total code". What you show is NOT the total code - it's missing a definition of plotopt.

Where did you get this code?
 
  • #6


Your plotop is input from the user.
type 'R' for plotting reflectivity,
'A' for absorptivity
or 'RA' for both
 
  • #7


how can i use this in code ?
 
  • #8


The link you gave was to an "m file", a file that defines a function that is called by other MATLAB code.

Look in the MATLAB documentation for how to call a function that is defined in another file.

The part that you left out in your post is shown below.

Code:
function fresnelplot(n1,n2,k2,plotopt)
%
% fresnelplot(n1,n2,k2,plotopt) 
% 
% plots the Fresnel reflectivities and/or absorptivities (s-pol, p-pol 
% and circ.) for light incident from a dielectric medium with 
% refractive index n1 on an opaque absorbing medium with complex refractive 
% index n2+i*k2.
%
% Input:  n1      - refractive index (medium 1)
%         n2      - refractive index (medium 2)
%         k2      - extinction coefficient (medium 2)
%         plotopt - plotting option (type 'R' for plotting reflectivity,
%                   'A' for absorptivity or 'RA' for both)
%
% Output: plots of reflectivities and/or absorptivities
%
% Last updated: 2011-10-26 (David Bergström)
%
 
  • #9


he says >>

plotopt - plotting option (type 'R' for plotting reflectivity,
'A' for absorptivity or 'RA' for both)

...

i know about m-file already !. but there's no function called (plotting option ) .so the problem is how can i use this in matlab. what is the function should i use for ?
on other hand there's no m-file attached , and i don't know the code for make a new one !
 
  • #10


error 401 said:
he says >>

plotopt - plotting option (type 'R' for plotting reflectivity,
'A' for absorptivity or 'RA' for both)

...

i know about m-file already !. but there's no function called (plotting option )
plotopt is not a function. It is a parameter in the fresnelplot function.
error 401 said:
.so the problem is how can i use this in matlab. what is the function should i use for ?
Open the link you posted (http://www.mysimlabs.com/matlab/auxiliary/fresnelplot.m ).
Copy the code at this link into any editor (Notepad or whatever).
Save to a file named fresnelplot.m in your MATLAB working directory.

Your MATLAB code that uses the fresnelplot function should look something like this:
Code:
n1 = input("Enter refractive index for medium 1")
n2 = input("Enter refractive index for medium 2")
k2 = input("Enter extinction coefficient for medium 2")
plotopt = input("Enter plot option")

fresnelplot(n1, n2, k2, plot)
.
.
.
For the plot option, you can enter R, A, RA, or AR.
error 401 said:
on other hand there's no m-file attached , and i don't know the code for make a new one !
 

Related to Error in defined expression for Fresnel equation in matlab ( please )?

What is the Fresnel equation?

The Fresnel equation is a mathematical relationship that describes the reflection and transmission of electromagnetic waves at an interface between two media with different refractive indices.

What does it mean to have an error in a defined expression?

An error in a defined expression means that there is a mistake or inconsistency in the way the equation is written, which can lead to incorrect results when using it for calculations.

What is the significance of the Fresnel equation in MATLAB?

The Fresnel equation is commonly used in MATLAB for simulations and calculations related to optics and electromagnetic waves. It allows for accurate modeling of the behavior of light at interfaces between different materials.

How can I troubleshoot an error in the Fresnel equation in MATLAB?

If you encounter an error in the Fresnel equation in MATLAB, you can start by checking for any typos or missing variables in the equation. You can also compare your code to a known, correct implementation of the equation to identify any discrepancies. Additionally, checking the units and data types of your variables can help pinpoint the source of the error.

Are there any common mistakes when using the Fresnel equation in MATLAB?

Some common mistakes when using the Fresnel equation in MATLAB include incorrectly defining variables, using the wrong equation or formula, and not converting units properly. It is important to carefully check your code and inputs to ensure accurate results.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
15K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top