Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Type mismatch in equation

Type mismatch in equation

Hi all,

I have a type mismatch error in my modelica code;

model basisFunction
  parameter Integer sn=5 "The number of the points in each axis";
  parameter Integer i=1;
  parameter Integer j=1;
  parameter Real c[2,1]=[0; 0];
  parameter Real theta_r[sn]=linspace(-0.02,0.02,sn) "Generates sn values for position";
  parameter Real theta_p[sn]=linspace(-0.1,0.1,sn)   "Generates sn values for velocity";
  parameter Real s[1,2]=[(theta_r[2]-theta_r[1])/1.7, (theta_p[2]-theta_p[1])/1.7]    "Determine the size of the basis function";
  parameter Real bFunc[sn*sn]=fill(1,sn*sn);
  parameter Real x[2,1]=[0.01; 0.09];
  parameter Real bPen[sn*sn]=zeros(sn*sn);
  // Calculate the basis function response
    equation
    for i in 1:size(theta_r,1) loop
      for j in 1:size(theta_p,1) loop
        c=[theta_r[i]; theta_p[j]]  "Centre of each basis";
        bFunc[(i-1)*size(theta_r,1)+j]=exp(-((1.0./(s)).^2)*((x-c).^2));
      end for;
    end for;
    bPen=bFunc/sum(bFunc);
    end basisFunction;

and the error mesage is ;

Error: Type mismatch in equation t[1]={{(1.0 / s[1,1]) ^ 2.0 * (x[1,1] - c[1,1]) ^ 2.0 + (1.0 / s[1,2]) ^ 2.0 * (x[2,1] - c[2,1]) ^ 2.0}} of type Real=Real[1, 1]
Error: Error occurred while flattening model basisFunction.

Could you help me to fix this problem please?
Thanks

Re: Type mismatch in equation

Left side is a scalar for each loop iteration, while the right side is a 1*1 matrix. Since it always has type [1,1], you can call

Code:

scalar()

on the right side (or re-write it to not generate an array expression).

Re: Type mismatch in equation

Thank you I think I saw my mistake...

There are 0 guests and 0 other users also viewing this topic