Friday, June 10, 2016

Optical Ray Tracing

ray_tracing
%==========================================================================
% Title: Ray tracing by matrix technique
% Author: Mahesha MG, Manipal Intitute of Technology Manipal University
% Date: 10/08/2015
%==========================================================================
% Variables
% r0 --> initial height from optic axis
% theta0 --> initial angle with normal
% M --> Propagation/Refraction matrix
%==========================================================================
clear;
clc;
D=zeros(1,20);
R=zeros(1,20);
r0 = input('Enter initial height from optic axis (in m): ');
theta0 = input('Enter initial angle with normal (in radian): ');
R0=[r0;theta0];
D=0;
td=0;
R=r0;
while(1)
    display('__________________OPTIONS__________________');
    display('0 --> Exit');
    display('1 --> Propagation');
    display('2 --> Refraction');
    display('3 --> Thin lens');
    display('4 --> Reflection');
    display('5 --> Spherical Mirror');
    display('____________________________________________');
    ch=input('Enter option: ');
    if ch == 0
    break;
    else if ch == 1
        d=input('Enter distance (in m): ');
        M=[1 d; 0 1];   %Propagation matrix
        else if ch == 2
                n0=input('Refractive index of first medium: ');
                n1=input('Refractive index of second medium: ');
                d=0;
                M=[1 0; 0 n0/n1];  %Refraction matrix
            else if ch == 3
                f=input('Focal length of the lens: ');
                d=0;
                M=[1 0; -1/f 1];   %Thin lens matrix
                else if ch == 4
                        d=0;
                        M=[1 0; 0 -1]; %Reflection matrix
                    else if ch == 5
                            d=0;
                            R=input('Enter radius of curvature of spherical mirror: ');
                            M=[1 0; -2/R -1];
        else warning('Entered option is invalid');
                        end
                    end
                end
            end
        end
    end
  R1=M*R0;
  td=td+d;
  D=[D;td];
  R=[R;R1(1)];
  R0=R1;
  end
figure('color','white');
plot(D,R,'b-+',D,-R,'r-+');
%==========================SAMPLE INPUT====================================
% Enter initial height from optic axis (in m): 0.02
% Enter initial angle with normal (in radian): 0.01
% __________________OPTIONS__________________
% 0 --> Exit
% 1 --> Propagation
% 2 --> Refraction
% 3 --> Thin lens
% 4 --> Reflection
% 5 --> Spherical Mirror
% ____________________________________________
% Enter option: 1
% Enter distance (in m): 0.1
% __________________OPTIONS__________________
% 0 --> Exit
% 1 --> Propagation
% 2 --> Refraction
% 3 --> Thin lens
% 4 --> Reflection
% 5 --> Spherical Mirror
% ____________________________________________
% Enter option: 3
% Focal length of the lens: 0.06
% __________________OPTIONS__________________
% 0 --> Exit
% 1 --> Propagation
% 2 --> Refraction
% 3 --> Thin lens
% 4 --> Reflection
% 5 --> Spherical Mirror
% ____________________________________________
% Enter option: 1
% Enter distance (in m): 0.1
% __________________OPTIONS__________________
% 0 --> Exit
% 1 --> Propagation
% 2 --> Refraction
% 3 --> Thin lens
% 4 --> Reflection
% 5 --> Spherical Mirror
% ____________________________________________
% Enter option: 0
% =========================================================================

Monday, September 21, 2015

Simulink - Damped Oscillation

Details for damped_oscillation

ODE for damped oscillation

22-Sep-2015 11:20:13

Model - damped_osc


Full Model Hierarchy
  1. damped_osc

Simulation ParameterValue
Solverode45
RelTol1e-3
Refine1
MaxOrder5
ZeroCrosson
[more info]

System - damped_osc




Table 1. Gain Block Properties
NameGainMultiplicationParam Data Type StrOut Data Type StrLock ScaleRnd MethSaturate On Integer Overflow
Gain1/mElement-wise(K.*u)Inherit: Inherit via internal ruleInherit: Inherit via internal ruleoffFlooroff
Gain1kElement-wise(K.*u)Inherit: Inherit via internal ruleInherit: Inherit via internal ruleoffFlooroff
Gain2cElement-wise(K.*u)Inherit: Inherit via internal ruleInherit: Inherit via internal ruleoffFlooroff

Table 2. Integrator Block Properties
NameExternal ResetInitial Condition SourceInitial ConditionAbsolute ToleranceZero CrossContinuous State Attributes
Integratornoneinternalautoon''
Integrator1noneinternal1autoon''

Table 3. Sum Block Properties
NameIcon ShapeInputsCollapse ModeCollapse DimInput Same DTAccum Data Type StrOut Data Type StrLock ScaleRnd MethSaturate On Integer Overflow
Addrectangular--All dimensions1offInherit: Inherit via internal ruleInherit: Inherit via internal ruleoffFlooroff

Appendix


Table 4. Block Type Count
BlockTypeCountBlock Names
Gain3Gain, Gain1, Gain2
Integrator2Integrator, Integrator1
Sum1Add
Scope1Scope