cancel
Showing results for 
Search instead for 
Did you mean: 

Can i write polynomial equation in STM32cubeIDE

Mohan1
Associate III

Hello,

I am trying to estimate initial SOC of battery by using a polynomial equation obtained from discharged voltage data of battery. I successfully run this polynomial equation in MATLAB but don't know how to write in STM32cubeIDE.

The obtained polynomial equation is-

p1 = 9.722*10^(-24);
p2 = -1.565*10^(-19);
p3 = 9.908*10^(-16);
p4 = -3.139*10^(-12);
p5 = 5.22*10^(-9);
p6 =-4.318*10^(-6);
p7 = 0.00127;
p8 = 3.709;
x=4;
j = p1*(x.^7)+p2*(x.^6)+p3*(x.^5)+p4*(x.^4)+p5*(x.^3)+p6*(x.^2)+p7*(x)+p8

Here 'j' is polynomial equation and 'x' is initial voltage of battery.

Thanks.

4 REPLIES 4

>> don't know how to write in STM32cubeIDE.

Write it in C

>> p1 = 9.722*10^(-24);

p1 = 9.722e-24;

>> j = p1*(x.^7)+p2*(x.^6)+p3*(x.^5)+p4*(x.^4)+p5*(x.^3)+p6*(x.^2)+p7*(x)+p8

j = p1*pow(x,7) + p2*pow(x,6) ...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mohan1
Associate III

@Community member​ Thanks for your response sir.

RMcCa
Senior II

You could also declare 2 vectors (1 dimensional arrays) and use arm_dot_prod_f32() to do all the multiplying and adding.

Declare p[8] and initialize all 8 values and x[8]. Set x[0] = 1.0 and then use a for loop to calculate the other x[]s as they are simply the input value * the previous x[].​

@RMcCa​ Thanks for your reply sir.