How can I adjust my function to have 3 variables which will alter the value of Um in a for loop and plug it back into my differential?

Here is my original function:
function df = optic(t,f) df = zeros(2,1);
h = 6.62606957e-34; % J
hbar = h/(2*pi); % J
eVJ = 1.602176565e-19; % J
delta = 24.35e-12*eVJ ; % J
d = 294.5e-9 ; % m
Vm = 25e-4; % 2.5 mm/s
lambdaM = 20*d; % m
Km = 2*pi/lambdaM; % /m
Wm = Vm*Km; % /s
Um = 250e-12*eVJ; % J - so Um is a constant at the moment - I need a for loop that will automatically and plug it in df(2)..
% tau = Wm*t;
C = 0.5*Km*delta*d/hbar;
D = 0.5*d*Um*Km/hbar;
df(1)= C*sin(f(2)); % Displacement
df(2)= D*cos(f(1)-Wm*t); % Momentum
end
If you create another script: this will produce the graph for the above data:
tspan = 0:1e-5:10e-3;
[t,f] = ode45(@optic, tspan, [0 , 0]);
figure; plot(t*1000,f(:,1),'g-'); xlabel ('Time / (ms)'); ylabel ('Displacement / (\mum)'); title('Optic Wave');
Now I need to have function df = optic(t,f,U) so new variable U changes from 1 to 200 eV. Therefore values of f(1) and f(2) will also change.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Asked:

on 16 Mar 2015

Edited:

on 16 Mar 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!