matrix form numerical integration

2 views (last 30 days)
john birt
john birt on 25 Apr 2012
This code does not work
clear;
x = [1.0024 0.264 1.4334 1.46 0.0219 0.1;
1.0024 0.264 1.435 1.46 0.0220 0.1;
1.0024 0.264 1.4352 1.46 0.0221 0.1;
1.0024 0.264 1.4353 1.46 0.0222 0.1;
1.0024 0.264 1.4354 1.46 0.0222 0.1;
1.0024 0.264 1.4357 1.46 0.0223 0.1];
r = x(:,1); Y = x(:,2); q = x(:,3); K=x(:,4); L=x(:,5); c=x(:,6);
t = 0.1:0.1:0.6;
z = trapz(t,normcdf(((log(q./K)+t.*c.^2./2)./(c.*sqrt(t))),0,1));
If I just use one line of records, i.e
z = trapz(t,normcdf(((log(q(1)./K(1))+t.*c(1).^2./2)./(c(1).*sqrt(t))),0,1));
Then it works!!! What I dont understand is how to do this 'trapz' for each line of records in the vector 'x'.

Accepted Answer

Thomas
Thomas on 25 Apr 2012
you are trying to perform trapezoidal numerical integration over a number of different values but the output z is not a vector.. MAybe you need something like this.. where you get a z for each line of input data..
clear;
x = [1.0024 0.264 1.4334 1.46 0.0219 0.1;
1.0024 0.264 1.435 1.46 0.0220 0.1;
1.0024 0.264 1.4352 1.46 0.0221 0.1;
1.0024 0.264 1.4353 1.46 0.0222 0.1;
1.0024 0.264 1.4354 1.46 0.0222 0.1;
1.0024 0.264 1.4357 1.46 0.0223 0.1];
r = x(:,1); Y = x(:,2); q = x(:,3); K=x(:,4); L=x(:,5); c=x(:,6);
t = 0.1:0.1:0.6;
for i=1:length(x)
z(i) = trapz(t,normcdf(((log(q(i)./K(i))+t.*c(i).^2./2)./(c(i).*sqrt(t))),0,1));
end

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!