writing a formula in matlab
Mostrar comentarios más antiguos
Hello all I have a formula that I want to write it in matlab but I don't know about sigma and Combination,can anyone help me please the formula is

i want to calculate 'C' amount but when it is less or equal with 0 'C=0' and when it is bigger than 0 C amount=the calculated amount all of the amounts (r,u,d,n,St-n,k) are given ('p' should calculate) and if it is possible I want to do it with xlsread for given data and rewrite C amount in the main excel file I don't know i explained it well or not :( thanks for all of your helps
1 comentario
amir khalighi
el 2 de Mayo de 2018
Respuestas (1)
Geoff Hayes
el 30 de Abr. de 2018
0 votos
11 comentarios
amir khalighi
el 1 de Mayo de 2018
amir khalighi
el 1 de Mayo de 2018
Geoff Hayes
el 2 de Mayo de 2018
amir - you will need to clarify what you mean by it's not working. Are you observing any errors? If so, what are they?
amir khalighi
el 3 de Mayo de 2018
amir khalighi
el 3 de Mayo de 2018
Geoff Hayes
el 4 de Mayo de 2018
I suspect part of the problem is with the square brackets around
[1/(1+r)^n]
in
C=[1/(1+r)^n]*(symsum((nchoosek(n,j))*p^j*(1-p)^(n-j)*max(0,((1+u)^j)*(1+d)^(n-j)*St/k)))
Try replacing with () brackets instead. Also, what is k as it seems undefined.
Unfortunately, I don't have the Symbolic Math Toolbox so cannot run the above code...which is why I suggested using a for loop.
amir khalighi
el 4 de Mayo de 2018
Geoff Hayes
el 4 de Mayo de 2018
Your for loop would look something like
n = 42;
for j = 0:n
% update C
end
As for when it is bigger than 0 what is it?
amir khalighi
el 4 de Mayo de 2018
amir khalighi
el 4 de Mayo de 2018
Editada: Geoff Hayes
el 5 de Mayo de 2018
Geoff Hayes
el 5 de Mayo de 2018
The error message is telling you that there is a problem with the brackets in your line of code - possibly too many. You may want something like
C=(1/(1+r)^n)*symsum(nchoosek(n,j)*p^j*(1-p)^(n-j)*max(0,((1+u)^j)*(1+d)^(n-j)*St/K),j,0,n)
Please verify which are the inputs to your symsum function call.
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!