# Thread: Help needed

1. ## Help needed

I'm using a C function in matlab simulink to get the output of non linear equation of the form y = x + e^x. Though I can't get through this after a big headache and a lot of effort. You are my last hope my friends, so thank you in advance.

Here is the code:
Code:
```void Sigma(const real_T *Tc,const real_T *Irradiance,const real_T *Vpv,const real_T *Ipv, real_T *I0)
{
real_T Irs, Is, J, Tcc;
(Ipv[0] < 0) ? (J=0) : (J = Ipv[0]);
Tcc = (Tc[0]) + 273.15; /* Celsius to Kelvin Trasformation*/
Irs = (IscRef) / (exp((q) * ((VocRef) + (beta) *((Tcc)-(Tref))) / ((Ns) * (K) * (eta) * (Tcc))) -1);
Is = (Irs) * (pow(Tcc/Tref, 3)) * exp( (q) * (Eg) * (1/(Tref) - 1/(Tcc))/((K) * (eta)));
I0[0] = (Np) * (((alpha) * ((Tcc) - (Tref)) + (IscRef)) * (Irradiance[0])/(Irradiance_ref)) -
((Is) * (exp((q) * ((Vpv[0])/(Ns) + (J) * (Rs)/(Np)) / ((K) * (Tcc) * (eta))) -1) +
((Np)/(Ns) * (Vpv[0]) + (J) * (Rs)) / (Rsh));
}```
All the parameters are defined externally as double.
Matlab has a C compiler installed and co-working with it in real time

Here is the builder error:
Code:
```Error PV_module_wrapper.c: 71  syntax error; found `{' expecting `;'
Error PV_module_wrapper.c: 71  skipping `{'
Error PV_module_wrapper.c: 75  operands of - have illegal types `double' and `pointer to const double'
Error PV_module_wrapper.c: 75  operands of * have illegal types `pointer to const double' and `int'
Error PV_module_wrapper.c: 75  operands of * have illegal types `pointer to const double' and `pointer to const double'
Error PV_module_wrapper.c: 75  operands of * have illegal types `pointer to const double' and `pointer to const double'
Error PV_module_wrapper.c: 75  operands of * have illegal types `int' and `pointer to const double'
Error PV_module_wrapper.c: 75  operands of / have illegal types `pointer to const double' and `double'
Error PV_module_wrapper.c: 76  operands of / have illegal types `double' and `pointer to const double'
Error PV_module_wrapper.c: 76  operands of * have illegal types `pointer to const double' and `pointer to const double'
Error PV_module_wrapper.c: 76  operands of / have illegal types `int' and `pointer to const double'
Error PV_module_wrapper.c: 76  operands of * have illegal types `pointer to const double' and `pointer to const double'
Error PV_module_wrapper.c: 77  undeclared identifier `I0'
Error PV_module_wrapper.c: 77  type error: pointer expected
Error PV_module_wrapper.c: 77  operands of - have illegal types `double' and `pointer to const double'
Error PV_module_wrapper.c: 77  operands of * have illegal types `pointer to const double' and `int'
Error PV_module_wrapper.c: 77  operands of * have illegal types `pointer to const double' and `double'
Error PV_module_wrapper.c: 77  operands of / have illegal types `int' and `pointer to const double'
Error PV_module_wrapper.c: 77  operands of * have illegal types `pointer to const double' and `int'
Error PV_module_wrapper.c: 78  operands of / have illegal types `double' and `pointer to const double'
Error PV_module_wrapper.c: 78  too many errors

C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Compile of 'PV_module_wrapper.c' failed.```

2. What are the following declared as?

IscRef
q
VocRef
beta
Tref
Ns
K
eta
Eg
Np
alpha
Irradiance_ref
Rs
Rsh

My bet is that one or more of them are pointers

3. Originally Posted by Click_here
What are the following declared as?

IscRef
q
VocRef
beta
Tref
Ns
K
eta
Eg
Np
alpha
Irradiance_ref
Rs
Rsh

My bet is that one or more of them are pointers
They are declared as double
IscRef = 8.03
VocRef = 30.4
beta = -0.00346
Tref = 25
Ns= 4
K = 1.38 * 10^-23
eta = 0.131
q= 1.6 * 10^-19
Eg = 1.76282 * 10^-19
Np = 2
alpha = 0.00057
Irradiance_ref = 1000
Rs = 0.004
Rsh = 10

4. Are these variables from your MATLAB program?

5. The canonical rule when dealing with any compiler is to fix the first error first and then recompile. This means you should look only at this line and ignore everything else until its fixed:

Code:
`Error PV_module_wrapper.c: 71  syntax error; found `{' expecting `;'`

6. Not exactly. It is a C function builder and you provide the c code for the output (the above code) separately from the parameters. These are parameters not variables.

7. Originally Posted by c99tutorial
The canonical rule when dealing with any compiler is to fix the first error first and then recompile. This means you should look only at this line and ignore everything else until its fixed:

Code:
`Error PV_module_wrapper.c: 71  syntax error; found `{' expecting `;'`
Is there a ';' needed in first line?
"void Sigma(...);" ?

8. Do you have a *.mat file?

See this link
https://maxwell.ict.griffith.edu.au/...ile_format.pdf
Look at the C example

9. Originally Posted by Prefas
Is there a ';' needed in first line?
"void Sigma(...);" ?
It's probably something from before the subroutine.

10. Originally Posted by Click_here
It's probably something from before the subroutine.
the part before this subroutine is automatically generated by matlab including initializing, calling methods and terminate.
I only have to write the mdlOutput subroutine which is pasted above

The above code seems fine to you?

11. Something is not right...

Have a look through here - Make sure you are doing everything right
C Shared Libraries - MATLAB & Simulink - MathWorks Australia

12. I use this type of block
S-Function Builder Dialog Box - MATLAB & Simulink

And the code goes at the "outputs pane" section

13. Try dereferencing the all the imported values
"`double' and `pointer to const double'"

They appear to be pointers.

14. Yeah!
before reading your comment I was trying this exactly

here is the code:
Code:
```void Sigma(const real_T *Tc,const real_T *Irradiance,const real_T *Vpv,const real_T *Ipv, real_T *I);
{
real_T Irs, Is, J, Tcc;
(Ipv[0] < 0) ? (J=0) : (J = Ipv[0]);
Tcc = (Tc[0]) + 273.15; /* Celsius to Kelvin Trasformation*/
Irs = (IscRef[0]) / (exp((q[0]) * ((VocRef[0]) + (beta[0]) *((Tcc)-(Tref[0]))) / ((Ns[0]) * (K[0]) * (eta[0]) * (Tcc))) -1);
Is = (Irs) * (pow(Tcc/Tref[0], 3)) * exp( (q[0]) * (Eg[0]) * (1/(Tref[0]) - 1/(Tcc))/((K[0]) * (eta[0])));
I[0] = (Np[0]) * ((((alpha[0]) * ((Tcc) - (Tref[0])) + (IscRef[0])) * (Irradiance[0])/(Irradiance_ref[0])) -
((Is) * (exp((q[0]) * ((Vpv[0])/(Ns[0]) + (J) * (Rs[0])/(Np[0])) / ((K[0]) * (Tcc) * (eta[0]))) -1) +
((Np[0])/(Ns[0]) * (Vpv[0]) + (J) * (Rs[0])) / (Rsh[0])));
}```
Is the ';' in the first line right?

the builder error:
Code:
```Error PV_module_wrapper.c: 76  undeclared identifier `I'
Error PV_module_wrapper.c: 76  type error: pointer expected
Warning PV_module_wrapper.c: 76   possible usage of I before definition
2 errors, 1 warnings

C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Compile of 'PV_module_wrapper.c' failed.```

15. Do not put ';' in the first line.

Popular pages Recent additions