Computing an integral inside a function
7 次查看(过去 30 天)
显示 更早的评论
Hi guys!
I need to compute an integral inside a function. To compute an integral I use int function, first argument of which is the function to be integrated. I specify this function inside my big function
function [Put]=Putprice(S,K,r,q,T,a1,a2,b1,b2,c,beta)
function y=b(s)
y=b1*s+b2;
end
alpha=r-q+b;
f=a^2*exp(-2*abs(beta)*int(alpha,s,0,u));
tau=int(f,u,0,T);
all the other parameters are specified. What's wrong?
Daniel.
0 个评论
回答(2 个)
Wayne King
2013-6-30
编辑:Wayne King
2013-6-30
It really helps when you show what error you are getting and how you are calling the function at the command line. Give people a simple example so that they can reproduce your error.
int() expects symbolic variables, are you using symbolic variables here?
If not, look at the help for integral()
value = integral(@(x) 1/sqrt(2*pi)*exp(-x.^2./2),0,3)
Shashank Prasanna
2013-6-30
Integral is for numerical integration. What are you expecting the result in?
Once you compute the symbolic integral use subs to evaluate the result:
Or use matlabFunction to convert the integrated function into a matlab function handle:
Ofcourse I am assuming that you know what the other parameters are.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!