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

Failed to elaborate expression

Failed to elaborate expression

Hi all,
I wrote a function and I have this error, "Failed to elaborate expression: bFunc / sum(bFunc)". If you notice my mistake, could you let me know please. Thanks. The function is:

function basisFunction
  input Real x[2,1];
  output Real bPen[sn*sn];
  protected Integer sn:=5 "The number of the points in each axis";
            Real c[2,1];   
            Real bFunc[sn*sn];
            Real theta_r[sn]:=linspace(-0.02,0.02,sn) "Generates sn values for position"; 
            Real theta_p[sn]:=linspace(-0.1,0.1,sn)   "Generates sn values for velocity";
            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";         
  // Calculate the basis function response
    algorithm
    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]:=scalar(exp(-((1.0./(s)).^2)*((x-c).^2)));
      end for;
    end for;
    bPen:=bFunc/sum(bFunc);
    end basisFunction;

Re: Failed to elaborate expression

Hi,

I can't see anything obviously wrong with your function, so this is most likely a bug in the compiler. I tried your model myself with the latest development version, but got another error instead. I'll investigate this further tomorrow and get back to you with my findings. Which version of OpenModelica are you using, and how do you call the function?

Re: Failed to elaborate expression

Hi,

Thanks for your help. I am using version 1.8.1, I think this is the latest version. I call the function "basisFunction([0.01; 0.1])". Actually, I am trying to generate a Modelica Custom Component to use in MapleSim, but I just wanted to test the function in Modelica before. Maybe this might work if I write this there. I will try and let you know if this works there.

Again thanks for your help

Re: Failed to elaborate expression

Hi again,

You say that you're using 1.8.1, but are you perhaps referring to the 1.8.1 beta? We actually released 1.8.1 yesterday, so you could try that version if you're not already using it. I fixed some issues with the sum operator between the 1.8.1 beta and the full 1.8.1 release that I think fixes your particular issues. You will run into other issues related to scalar exponents on arrays, but I'm looking into fixing those right now.

Re: Failed to elaborate expression

We had some issues with scalar operations on matrices. I've fixed those now, and your function now works as it should for me. I assume your using Windows, so I'll see if I can get a new nightly build up for you.

Re: Failed to elaborate expression

Thanks for your help Perost. I am trying to generate a Modelica Custom Component for MapleSim. Do you think when you sorth this problem out, I will be able to run this in MapleSim? I returned this as a "model"  rather than "function" as below;

model basisFunction
    extends Maplesoft.Icons.CustomComponent;
    parameter Real x[2,1] "The input from multibody system";
              Real bPen[sn*sn] "The normalized output for the basis function";
              Integer sn=5 "The number of samples in each axist";
              Real c[2,1] "Centre of each basis";
              Real bFunc[sn*sn] "The basis function";
              Real theta_r=linspace(-0.02,0.02,sn) "Generates sn values for position";
              Real theta_p=linspace(-0.1,0.1,sn) "Generates sn values for velocity";
              Real s[1,2]=[(theta_r[2]-theta_r[1])/1.7, (theta_p[2]-theta_p[1])/1.7];
    Modelica.Blocks.Interfaces.RealInput x[2,1] annotation (Placement(transformation(
        extent = {
            {-110, 32},
            {-90, 52}},
        rotation = 0)));
    Modelica.Blocks.Interfaces.RealOutput bPen[sn*sn] annotation (Placement(transformation(
        extent = {
            {-110, -51},
            {-90, -31}},
        rotation = 0)));
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]];
          bFunc[(i-1)*size(theta_r,1)+j]=scalar(exp(-((1.0./s).^2)*(x-c).^2));
       end for;
    end for;
    bPen=bFunc/sum(bFunc);
    annotation (uses(Modelica(version = "3.1")));
end basisFunction;

This has not worked. Can you see any clear mistake here?

Thanks again...

Re: Failed to elaborate expression

Hi,

A new nightly build is now available which should fix your problems, download it here. Unfortunately I know nothing about MapleSim, so I can't help you there. Your model defines x and bPen twice though, which is illegal.

There are 0 guests and 0 other users also viewing this topic
You are here: