matrix form numerical integration

2 vues (au cours des 30 derniers jours)
john birt
john birt le 25 Avr 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'.

Réponse acceptée

Thomas
Thomas le 25 Avr 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
  1 commentaire
john birt
john birt le 25 Avr 2012
thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by