[Scilab-users] Vectorization issue

Rafael Guerra jrafaelbguerra at hotmail.com
Thu May 26 12:26:05 CEST 2016


 
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)
<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/2550dc69/attachment.htm>


More information about the users mailing list