matrix form numerical integration

조회 수: 13(최근 30일)
john birt
john birt 2012년 4월 25일
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'.

채택된 답변

Thomas
Thomas 2012년 4월 25일
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
  댓글 수: 1
john birt
john birt 2012년 4월 25일
thank you.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by