Re: [Scilab-users] Loop query

2021-08-16 Thread Lester Anderson
This is the simplest option, based on primes(35): [p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11]=seq([1:$]); Extract values based on the indices in the seq list. On Mon, 16 Aug 2021 at 10:49, Lester Anderson wrote: > Hi Samuel, > > Further to your method, is there a way to vectorise the list output based

Re: [Scilab-users] Loop query

2021-08-16 Thread Lester Anderson
Hi Samuel, Further to your method, is there a way to vectorise the list output based on the indices? One can access the elements as seq(1), seq(5) etc. I did look at list2vec(seq), but as documented this creates a single column vector. Thanks Lester On Sun, 15 Aug 2021 at 14:55, Samuel Gougeon

Re: [Scilab-users] Loop query

2021-08-15 Thread Lester Anderson
Thanks for all the guidance guys! Lester On Sun, 15 Aug 2021 at 15:33, Stefan Du Rietz wrote: > > > On 2021-08-15 15:54, Samuel Gougeon wrote: > > Le 15/08/2021 à 11:28, Lester Anderson a écrit : > >> Hello Samuel, > >> > >> The size of ns (number of steps) and seq (sequence of values) are > >>

Re: [Scilab-users] Loop query

2021-08-15 Thread Stefan Du Rietz
On 2021-08-15 15:54, Samuel Gougeon wrote: Le 15/08/2021 à 11:28, Lester Anderson a écrit : Hello Samuel, The size of ns (number of steps) and seq (sequence of values) are variable depending on the integer input, and this seems to be one issue. For this reason, seq must be a list, leading

Re: [Scilab-users] Loop query

2021-08-15 Thread Stefan Du Rietz
One solution: // Run the last (largest): [ns, seq] = collatz(prime($)) // insert in new zeros vector: ns = [zeros(prime-1), ns] // insert seq in new zeros matrix: seq = [zeros(length(seq), length(ns)-1), seq]; for i = 1:length(prime)-1 // Run collatz to get the new ns: [nsi, seqi] = collat

Re: [Scilab-users] Loop query

2021-08-15 Thread Samuel Gougeon
Le 15/08/2021 à 11:28, Lester Anderson a écrit : Hello Samuel, The size of ns (number of steps) and seq (sequence of values) are variable depending on the integer input, and this seems to be one issue. For this reason, seq must be a list, leading to function [ns, seq] = collatz(p) seq

Re: [Scilab-users] Loop query

2021-08-15 Thread Lester Anderson
Hi Stefan, Thank you for clarifying the meaning of the error message. Lester On Sun, 15 Aug 2021 at 11:59, Stefan Du Rietz wrote: > Hello Lester, > the problem is that seq in each loop is a vector of increasing length! > > Stefan > > > On 2021-08-15 12:05, Lester Anderson wrote: > > Hi Stefan,

Re: [Scilab-users] Loop query

2021-08-15 Thread Stefan Du Rietz
Hello Lester, the problem is that seq in each loop is a vector of increasing length! Stefan On 2021-08-15 12:05, Lester Anderson wrote: Hi Stefan, I did try that before, but got an error - "Submatrix incorrectly defined" Lester On Sun, 15 Aug 2021 at 10:56, Stefan Du Rietz

Re: [Scilab-users] Loop query

2021-08-15 Thread Lester Anderson
Hi Stefan, I did try that before, but got an error - "Submatrix incorrectly defined" Lester On Sun, 15 Aug 2021 at 10:56, Stefan Du Rietz wrote: > > > On 2021-08-15 09:00, Lester Anderson wrote: > > Hello, > > > > Basic query. I have a simple code that applies the Collatz conjecture > > equati

Re: [Scilab-users] Loop query

2021-08-15 Thread Stefan Du Rietz
On 2021-08-15 09:00, Lester Anderson wrote: Hello, Basic query. I have a simple code that applies the Collatz conjecture equation (3n+1) by running a function and then runs a loop over the values stored in prime (the first 8 Prime numbers): clear exec('collatz.sci',-1); prime = primes(

Re: [Scilab-users] Loop query

2021-08-15 Thread Lester Anderson
Hello Samuel, The size of ns (number of steps) and seq (sequence of values) are variable depending on the integer input, and this seems to be one issue. So I guess the problem is how to allocate dynamic arrays where you do not know the final size? This is a direct translation of a Matlab function

Re: [Scilab-users] Loop query

2021-08-15 Thread Samuel Gougeon
Le 15/08/2021 à 09:00, Lester Anderson a écrit : Hello, Basic query. I have a simple code that applies the Collatz conjecture equation (3n+1) by running a function and then runs a loop over the values stored in prime (the first 8 Prime numbers): clear exec('collatz.sci',-1); prime = prime

[Scilab-users] Loop query

2021-08-15 Thread Lester Anderson
Hello, Basic query. I have a simple code that applies the Collatz conjecture equation (3n+1) by running a function and then runs a loop over the values stored in prime (the first 8 Prime numbers): clear exec('collatz.sci',-1); prime = primes(20); for i = 1:length(prime) [ns, seq]=collatz(pri

Re: [Scilab-users] Loop query - Scilab 5.5.2

2016-01-18 Thread Tim Wescott
Or you can build a three column array as a matrix. Here's my example, but I don't see where 'x' is defined. Te = (5000:1:25000)'; D = E * Te .^ 3 / (12 * (1 - v^2)); lambda = ((rho_m - rho_fill) * g ./ (4 * D)) .^ 0.25; lambda_k = lambda * 1000; flex = (2 * Pb * lamda / ((rho_m-rho_fill)*g))

Re: [Scilab-users] Loop query - Scilab 5.5.2

2016-01-18 Thread Lester Anderson
Thanks for the solution(s). Had to change the flex line to get it working in 5.5.2: flex = 2*Pb*lamda/((rho_m-rho_fill)*g)*exp(-lamda_k*x).*cos(lamda_k*x); Otherwise it gave an error of undefined variable (flex). The three column array did not work; looking it to that one. checked x=linspace(0,

Re: [Scilab-users] Loop query - Scilab 5.5.2

2016-01-18 Thread Serge Steer
The plot instruction should be inside de loop k=0; st=["r","g","b"]; for Te = 5000:1:25000 // start: step: end k=k+1 D = E*Te .^3/(12*(1-v^2)); lamda = ((rho_m-rho_fill)*g ./(4*D)).^0.25; lamda_k = lamda*1000; flex = [flex,2*Pb*lamda/((rho_m-rho_fill)*g)*exp(-lamda_k*x).*

Re: [Scilab-users] Loop query - Scilab 5.5.2

2016-01-18 Thread Lester Anderson
Thanks for that pointer. The plot works but only does Te=25 in this case for Te = 5000:1:25000 // start: step: end D = E*Te .^3/(12*(1-v^2)); lamda = ((rho_m-rho_fill)*g ./(4*D)).^0.25; lamda_k = lamda*1000; flex = 2*Pb*lamda/((rho_m-rho_fill)*g)*exp(-lamda_k*x).*cos(lamda_k*x

Re: [Scilab-users] Loop query - Scilab 5.5.2

2016-01-18 Thread sgougeon
Hello, >for Te = 5000:25000:1 // start:end:step to make 5000, 15000, 25000 The syntax is start:step:end, not start:end:step https://help.scilab.org/docs/5.5.2/en_US/colon.html Samuel Gougeon ___ users mailing list users@lists.scilab.org http://li

[Scilab-users] Loop query - Scilab 5.5.2

2016-01-18 Thread Lester Anderson
Hello, I am trying to create a loop to plot three curves from an input variable (Te): clear() rho_m = 3330; rho_fill = 2400; g = 9.81; Pb = -1.5e12; v = 0.25; E = 1e11; x=linspace(0,200,41); for Te = 5000:25000:1 // start:end:step to make 5000, 15000, 25000 D = E*Te .^3/(12*(1-v^2));