I have a code in which the variable changes in every loop iteration for a fixed time point t=5, by assuming that x is changing between 0 and 5, and t=0 to 30. how can I plot the changes ?

r = 0.02;
mu = 0.08;
sigma = 0.2;
T = 30;
rho = 0.02;
for x = 0: 1: 5
t = 5;
for i = 1:30
gamma (i) = 5+ (0.07 * t (i));
end
f (t) = (exp (-rho * t) / gamma (i)). * exp (((1-gamma (i)) / gamma (i)). * (r + (mu - r) ^ 2 / (2 * sigma ^ 2. * Gamma (i))). * (T - t));
v1 (t, x) = (f (t). ^ gamma (i)). * (x. ^ (- gamma (i)));
v2 (t, x) = -gamma (i). * (f (t). ^ gamma (i)). * (x. ^ (1-gamma (i)));
c1 (t, x) = (exp (-rho * t) / gamma (i)) * x * f (t) ^ (- 1);
end
plot (x, c1)

 Accepted Answer

I found some mistakes in your code. Look

6 Comments

In this case I want to show that gamma is time dependent and for x between 0 and 5,by ignoring i from gamma (i) = 5+ (0.07 * t (i)) does it mean the same?
yes you right, therefore if I want to develope the code to three cases as below, I mean there should be specific f,v1,v2 and c1 with the same formula for gammaB and gammaC then how can I creat the loop such that plot (x, c1,x,c2,x,c3) wrt to three cases of gamma for a fixed point eg t = 5?
gammaA (i) = 4;
gammaB (i) = 5+ (0.07 * t (i));
gammaC (i) = 5- (0.07 * t (i));
Why are you talking about 3 cases? I see 30
for i = 1:30
gamma (i) = 5+ (0.07 * t (i));
end
what I wrote firstly is the primary code but for developing the code to three cases of gamma then its a bit complicated. Then you mean the loop for i = 1:30 should be removed for considering three cases?
If t then gamma is fixed also. So yes, for loop can be removed
gamma = 5+0.07*t;

Sign in to comment.

More Answers (0)

Asked:

on 10 Apr 2020

Commented:

on 10 Apr 2020

Community Treasure Hunt

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

Start Hunting!