I am new to advanced category of arduino (did LED blink only in past). I am programming something and I am kinda stuck in between about the logic.
I want to use this formula, W0 = (Wa + Wb)/(1-(Wf/W0)-(We/W0);
now variable W0 on left and right hand side of the equation is same. The way this function works is that user enters initial value of W0 and putting It in equation, it gives new value and loop continues, by keep updating with new value it comes to convergence after some some 30-40 iteration.
My question is, while putting (initial guess) float W0=1; and then running it through equation gives new value in void loop(), but when it comes to 1st line again W0 will be converted to 1. I don't want that!
Basically code is far from final version, basically I am learning kalman filter, here equation for 'c' is just one of many equations which eventually give new values for X0[4] variable, along with some new data
In file included from C:\Users\chinm\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:32:0,
from C:\Users\chinm\AppData\Local\Temp\arduino\sketches\E511F3C1C59241FE36B5CB662F6076FA\sketch\sketch_nov3d.ino.cpp:1:
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino: In function 'void setup()':
C:\Users\chinm\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/binary.h:23:12: error: expected unqualified-id before numeric constant
#define B0 0
^
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:5:7: note: in expansion of macro 'B0'
float B0=1;
^~
C:\Users\chinm\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/binary.h:31:12: error: expected unqualified-id before numeric constant
#define B1 1
^
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:6:7: note: in expansion of macro 'B1'
float B1=0;
^~
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino: In function 'void loop()':
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:15:22: error: 'B2' was not declared in this scope
float X0[4]={B0,B1,B2,B3}
^~
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:15:22: note: suggested alternative: 'A2'
float X0[4]={B0,B1,B2,B3}
^~
A2
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:15:25: error: 'B3' was not declared in this scope
float X0[4]={B0,B1,B2,B3}
^~
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:15:25: note: suggested alternative: 'A3'
float X0[4]={B0,B1,B2,B3}
^~
A3
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:23:22: error: 'w1' was not declared in this scope
float A[4][4]= {{1,(-w1*dt)/2,(-w2*dt)/2,(-w3*dt)/2},
^~
C:\Users\chinm\AppData\Local\Temp\.arduinoIDE-unsaved2024103-26608-io1en.b01gi5\sketch_nov3d\sketch_nov3d.ino:23:22: note: suggested alternative: 'w3'
float A[4][4]= {{1,(-w1*dt)/2,(-w2*dt)/2,(-w3*dt)/2},
^~
w3
exit status 1
Compilation error: 'B2' was not declared in this scope
Besides the predefined Bxxx variables that @jremington identified, If you intend to share variables between setup() and loop(), they need to have a wider scope. Otherwise the will be discarded when setup() completes.
Declare them as globals before you define setup().
As @jremington mentioned, unfortunately the identifiers B0 and B1 are already defined for another purpose in Arduino language, so you can't use them as variable names.
B2 and B3 are available to use, which is why you may notice that the error messages about them are different to the error messages about B0 and B1.
However, in this code, B2 and B3 are local to setup(). As soon as setup finishes executing, B2 & B3 cease to exist. That's why they cannot be seen or used in loop().
If you want your variables to be used in more than one function, you need to make them global variables by defining them outside of any function.
yes thanks guys. @jremington@DaveX . your solution works. I have one final question though, if I set static global variable, will it be called once (1st time) only? and not the second time onwards loop continues?
I have tried your suggestions and error got vanished.
by calling here I mean I need new values of the variable each time loop runs ( I will evantully get new values of i,j,k and l by some equations later in code) and not the initial values I set as global variables (i.e, i,j,k,l as 1,0,0,0) at the beginning.
Perfact, Thank you so much I got answers to all my questions. I didn't expected to get solution this fast. you guys are gem. Keep up the good work! and again thank you so much guys!