Help needed

This is a discussion on Help needed within the C Programming forums, part of the General Programming Boards category; I'm using a C function in matlab simulink to get the output of non linear equation of the form y ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    12

    Question 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.
    Last edited by Prefas; 02-18-2013 at 03:24 PM.

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    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
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    12
    Quote Originally Posted by Click_here View Post
    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. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    Are these variables from your MATLAB program?
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    1,118
    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. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    12
    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. #7
    Registered User
    Join Date
    Feb 2013
    Posts
    12
    Quote Originally Posted by c99tutorial View Post
    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. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    Do you have a *.mat file?

    See this link
    https://maxwell.ict.griffith.edu.au/...ile_format.pdf
    Look at the C example
    Fact - Beethoven wrote his first symphony in C

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    Quote Originally Posted by Prefas View Post
    Is there a ';' needed in first line?
    "void Sigma(...);" ?
    It's probably something from before the subroutine.
    Fact - Beethoven wrote his first symphony in C

  10. #10
    Registered User
    Join Date
    Feb 2013
    Posts
    12
    Quote Originally Posted by Click_here View Post
    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?
    Last edited by Prefas; 02-18-2013 at 04:38 PM.

  11. #11
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    Something is not right...

    Have a look through here - Make sure you are doing everything right
    C Shared Libraries - MATLAB & Simulink - MathWorks Australia
    Fact - Beethoven wrote his first symphony in C

  12. #12
    Registered User
    Join Date
    Feb 2013
    Posts
    12
    I use this type of block
    S-Function Builder Dialog Box - MATLAB & Simulink

    And the code goes at the "outputs pane" section

  13. #13
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    Try dereferencing the all the imported values
    "`double' and `pointer to const double'"

    They appear to be pointers.
    Fact - Beethoven wrote his first symphony in C

  14. #14
    Registered User
    Join Date
    Feb 2013
    Posts
    12
    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. #15
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,421
    Do not put ';' in the first line.
    Fact - Beethoven wrote his first symphony in C

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Needed
    By tvenki in forum C Programming
    Replies: 2
    Last Post: 08-13-2003, 03:18 AM
  2. Help needed.
    By saravanan_ts in forum Windows Programming
    Replies: 7
    Last Post: 08-06-2003, 09:18 AM
  3. Help Needed...
    By Akaii in forum C Programming
    Replies: 4
    Last Post: 08-02-2003, 11:45 PM
  4. Help needed
    By nightingale in forum C Programming
    Replies: 10
    Last Post: 07-15-2003, 01:20 AM
  5. Help Needed
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 06-14-2002, 01:38 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21