 # How to use equations in arduino

i have a code matlab and I want to translate to arduino code
i have problemes with equation like this
`x(1)=0.789632145698; n= 16 ; for i=2:n x(i)=r*(x(i-1)*(1-x(i-1))); end`

can anyone help me please

What are the problems you have?

Please remember to use code tags when posting code

1 Like

i want to use this function

x(i)=r*(x(i-1)*(1-x(i-1)));

but i don't now how i code it in arduino

I'm new her i don't naw haw i use code tags

thank you Mr

Hi,
r means radians?

RV mineirin

``````x[i] = r * (x[i-1] * (1 - x[i-1]));
``````

?

``````const size_t n = 16;
float x[n];  // array indices start at 0 so only 0 to 15 valid
x = 0.789632145698;
float r = 4.0;
for (size_t i = 1; i<=n-1; i++) {
x[i]=r*(x[i-1]*(1-x[i-1]));
}
``````

look at the example sketches that code with the IDE for how to create a full program and how to print results.

1 Like

i use this code but i have errer in IDE

'x' does not name a type

yes like this but the problme is 1 first valeur x(0) how i initialise it

Please post the code the is giving the error. Using the code tags </>

Can you post the full sketch?

OK, try transferring it to an Arduino sketch (which board are you using?)
and post that code.

ok now get it to compile, you will need to change the b(.. ) to b and change the indexing to 0 offset.
Also note that the loop() gets run over and over for ever so if you want to do this just once put it in the setup() which only gets run once on reboot

yes I want a lope () , I don't naw how to change b(...)

I don't think you want that type of loop() I think you just want a for loop to run and to completion and then the program to stop.
But you can sort that out later.
First in matlab the b(..) is indexing the array b using the value inside the ( ).
In C/C++, i.e. Arduino instead of ( ) is used. It is just a different syntax (different way of writing the same thing)
BUT remember in C/C++ the indexing counts from 0 == first location
So try those edits
Edit - off for a few hours. Coming to grips with Arduino will take a bit of work and time.
Read through arduino programming notebook

Thanks brother, I appreciate your help.
I'm doing a project and using a keypad to input letters, then I'm doing cryptage and sending them using moudul RF, so I use loop () ..

Please if you have any ideas on how to fix the code . lette me know thnx

Sorry for the offtopic, but what is supposed to be there at the end after the second "b"?
I see just a square (missing font maybe?), and the quote omits it entirely...

1 Like

Change

``````b ( )
``````

to

``````b [  ]
``````

(This crappy forum "mark-any-way-but-up" is infuriating)

``````// r = 4
// x(1)=0.789632145698; n= 16 ; for i=2:n x(i)=r*(x(i-1)*(1-x(i-1))); end
float x(int i)
{
if (i <= 1)
return 0.789632145698;

return 4.0 * ( x(i - 1) * (1 - x(i - 1)) );
}
``````
1 Like

To iterate is human, to recurse, divine

1 Like

Thanks brother, I appreciate your help.