1 view (last 30 days)

Star Strider
on 17 Sep 2019

Edited: Star Strider
on 17 Sep 2019

One approach:

gammav = linspace(0.5, 1, 10);

for k = 1:numel(gammav)

UE{k} = Explicit(S,sigma,r,T,M,K,gammav(k),N);

end

I have no idea what ‘Explicit’ is or what it produces, so it could be possible to vectorise this (instead of using the loop) depending on how you wrote the function. I am also saving each iteration to a cell array for that reason.

EDIT —

Plotting it depends on what ‘UE’ is. If ‘Explicit’ produces a scalar, this works:

figure

plot(gammav, [UE{:}])

grid

If it produces vectors or matrices, it will be necessary to use other approaches.

Star Strider
on 17 Sep 2019

This works, however, ‘UE’ is uniformly 0 for all values of ‘gammav’.

gammav = linspace(0.5, 1, 10);

for k = 1:numel(gammav)

[UE(:,k),A]=Explicit(S,sigma,r,T,M,K,gammav(k),N);

end

figure

plot(gammav, UE, '.r')

This code runs without errors.

Star Strider
on 17 Sep 2019

My pleasure!

If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

John D'Errico
on 17 Sep 2019

Using gamma as the name of a variable is a bad idea. Regardless,...

Where is the problem? Just substitute a range of values for gamma. Save the solution for each gamma. Then plot, with gamma on the x axis, and your solution on the y axis. WTP?

You can even use tools like fimplicit, which will do the hard work for you. For example,

f = @(gam,y) gam.^2 - y.^2 - 2*gam.*y.^3 + gam.*y + 1;

fimplicit(f)

xlabel 'gam'

ylabel 'y'

grid on

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.