Script error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Script error

Stefano Milani
Dear all,

I'm new user of octave and I need an help with this script.

%script per definizione passo fori lamiera

d=6; %Diametro dei fori
p=15; %Passo (da iterare)
p1=p*cos(pi/3); %Passo in direzione assiale (affinchè il pattern sia triangolare equilatero)
r2=622.5; % Diametro Max cono
r1=36; % Diametro Min cono
L=2610; % Lunghezza Lamiera
alpha=atan((r2-r1)/L); %Angolo di semiapertura Cono
rm=(r2+r1)/2; %Raggio medio cono
S=2*pi*rm*L; %Superficie Lamiera
Sforata=0.362*S; %Superficie forata
Nfori=Sforata/(pi*d^2/4); %Numero di fori
n=(L-2*p1)/p1+1;
r(1)=r2-p1*tan(alpha);
for i=1:n
 r(i+1) = r(i) - p1*tan(alpha);
 f(i) = 2*pi*r(i)/p;
end

When I run it I receive this message:

error: r(347): subscripts must be either integers 1 to (2^31)-1 or logicals
error: called from
    pattern at line 17 column 10


But I however obtain series number.
How can I solve this problem? Where I'm wrong?

Best regards

_______________
Stefano Milani
Structural Design Specialist
Ener Consulting S.r.l.



Reply | Threaded
Open this post in threaded view
|

Re: Script error

Dmitri A. Sergatskov


On Sun, Mar 18, 2018 at 8:08 AM, Stefano Milani <[hidden email]> wrote:

n=(L-2*p1)/p1+1;

​n is double​

 
r(1)=r2-p1*tan(alpha);
for i=1:n
 r(i+1) = r(i) - p1*tan(alpha);
 f(i) = 2*pi*r(i)/p;
end

When I run it I receive this message:

error: r(347): subscripts must be either integers 1 to (2^31)-1 or logicals
error: called from
    pattern at line 17 column 10


But I however obtain series number.
How can I solve this problem? Where I'm wrong?


​n is double, but it "​must be either integers 1 to (2^31)-1 or logicals"

You can do something like n=int32((L-2*p1)/p1+1);


Best regards

_______________
Stefano Milani
Structural Design Specialist
Ener Consulting S.r.l.


​Dmitri.
--
 


Reply | Threaded
Open this post in threaded view
|

Re: Script error

marco atzeri-2
In reply to this post by Stefano Milani
On 18/03/2018 14:08, Stefano Milani wrote:
> Dear all,
>
> I'm new user of octave and I need an help with this script.

Hi Stefano,

>
> %script per definizione passo fori lamiera
>
> d=6; %Diametro dei fori
> p=15; %Passo (da iterare)
> p1=p*cos(pi/3); %Passo in direzione assiale (affinchè il pattern sia
> triangolare equilatero)
> r2=622.5; % Diametro Max cono
> r1=36; % Diametro Min cono
> L=2610; % Lunghezza Lamiera
> alpha=atan((r2-r1)/L); %Angolo di semiapertura Cono
> rm=(r2+r1)/2; %Raggio medio cono
> S=2*pi*rm*L; %Superficie Lamiera
> Sforata=0.362*S; %Superficie forata
> Nfori=Sforata/(pi*d^2/4); %Numero di fori
> n=(L-2*p1)/p1+1;

the problem is here, due to math rounding the
n is not an exact integer as you would expect

octave:21> n=(L-2*p1)/p1+1
n =  347.00
octave:22> n-347
ans =   -5.6843e-14

So you can replace the instruction with:
n=round((L-2*p1)/p1+1);

> Best regards
>
> _______________
> Stefano Milani

Regards
Marco



Reply | Threaded
Open this post in threaded view
|

Re[2]: Script error

Stefano Milani
In reply to this post by Dmitri A. Sergatskov
I solve it: thank.

But why I obtain this error message? double number have a range number that contain int32.

Best regards



_______________
Stefano Milani
Structural Design Specialist
Ener Consulting S.r.l.

------ Messaggio originale ------
Da: "Dmitri A. Sergatskov" <[hidden email]>
A: "Stefano Milani" <[hidden email]>
Cc: "Octave Help" <[hidden email]>
Inviato: 18/03/2018 16:17:31
Oggetto: Re: Script error



On Sun, Mar 18, 2018 at 8:08 AM, Stefano Milani <[hidden email]> wrote:

n=(L-2*p1)/p1+1;

​n is double​

 
r(1)=r2-p1*tan(alpha);
for i=1:n
 r(i+1) = r(i) - p1*tan(alpha);
 f(i) = 2*pi*r(i)/p;
end

When I run it I receive this message:

error: r(347): subscripts must be either integers 1 to (2^31)-1 or logicals
error: called from
    pattern at line 17 column 10


But I however obtain series number.
How can I solve this problem? Where I'm wrong?


​n is double, but it "​must be either integers 1 to (2^31)-1 or logicals"

You can do something like n=int32((L-2*p1)/p1+1);


Best regards

_______________
Stefano Milani
Structural Design Specialist
Ener Consulting S.r.l.


​Dmitri.
--