[Scilab-users] [EXTERNAL] Re: Vectorization issue
Carrico, Paul
paul.carrico at esterline.com
Thu May 26 12:38:13 CEST 2016
Thanks Rafael for the answer
One explanation of the error is that I used a and b letter instead of aa and bb in your example; your code, if I change aa -> a and bb -> it fails again ... why ? (I do not understand)
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
De : users [mailto:users-bounces at lists.scilab.org] De la part de Rafael Guerra
Envoyé : jeudi 26 mai 2016 12:26
À : 'Users mailing list for Scilab'
Objet : [EXTERNAL] Re: [Scilab-users] Vectorization issue
Hi Paul,
It seems that there may be some issues with the .*, .^ syntax and also the use of the same variable in different context (b).
Editing the vectorization part of your code as follows:
// using vectorization
aa = [0:n]';
bb = ones(n,1);
i = aa.*.bb;
j = bb.*.aa;
Km2 = zeros(n*(n+1),1);
Km2 = %pi^6*((2*i+1).^2 .* j.^2).*((2*i+1).^2.*(b/2*d)^2 + j.^2) ;
Km2 = (144*(b/d).^4)/ sum(Km2);
Km2 = 1.2 + (nu/(1+nu))*Km2;
k2 = 1/Km2
produces:
k = 0.8333090
k2 = 0.8333333
A small difference. I did not check the formulas but it might be numerical error only.
Regards,
Rafael
From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of Carrico, Paul
Sent: Thursday, May 26, 2016 11:30 AM
To: International users mailing list for Scilab. (users at lists.scilab.org<mailto:users at lists.scilab.org>) <users at lists.scilab.org<mailto:users at lists.scilab.org>>
Subject: [Scilab-users] Vectorization issue
Dear
I failed in using vectorization in the example immediately bellow; but I do not remember if it's possible : any advice ?
Thanks
Paul
######################################################################################
mode(0)
n = 20
Km = 0;
b = 100;
d = 20;
nu = 0.3;
// using loops
for i = 0 : n
for j = 1 : n
Km = Km + (144*(b/d)^4)/( %pi^6*(2*i+1)^2*j^2*((2*i+1)^2*(b/2*d)^2+j^2) );
end
end
Km = 1.2 + (nu/(1+nu))*Km
k = 1/Km
// using vectorization
a = [0:n]';
b = ones(n,1);
i = a.*.b;
j = b.*.a;
Km2 = zeros(n*(n+1),1);
//toto = i. *j
Km2 = ( %pi.^6*((2*i+1).^2. * j.^2)*((2*. i+1).^2*(b/2*d).^2 + j^2) )
Km2 = (144*(b/d).^4)/ Km2
Km2 = 1.2 + (nu/(1+nu))*Km2
k2 = 1/Km2
EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160526/09af035e/attachment.htm>
More information about the users
mailing list