Plotting e^{t + W(t)/2} by calling W(t) function file

I'm trying to plot/figure out why this file isn't working out the way I wanted it to. I have to plot e^{t + W(t)/2} and I'm calling W(t) from a previous file as seen from the brownianPath(T,n). It gives me an exponential curve, which I think isn't what is supposed to happen because when I try to find the mean and plot that, it gives me an error. Thank you.
function [U] = expBrownianPath(T,n)
s = T/n;
t = 0:s:T;
U = zeros(1,n);
W = zeros(1,n);
for j = 2:n
W(j) = brownianPath(T,n);
U(j) = exp(j + (W(j)/2));
end
plot([0:s:T],[0 U], 'g-');
end

 Risposta accettata

U(j) = exp(j + (W(j)/2));
should use
U(j) = exp(t(j) + (W(j)/2));
and your plot should be plot(t, U)

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by