How to write a function to return matrix in Arduino IDE?

// Mine code is like that,

#include<BasicLinearAlgebra.h>
using namespace BLA;

void setup() {

Serial.begin(9600);
}

void loop() {

Matrix<2, 2>K = matrix(1.1);
}

float matrix(float phi)
{
Matrix<2, 2>M = {cos(phi), -sin(phi), sin(phi), cos(phi)};
return M;
}

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)

—-

What’s the type you want to return ? What’s the type you actually return?

Usually it’s best to let the owner of the instance create it (allocate the memory) and hand it over as a reference to the function you want to use/operate on the instance

You are telling the compiler that the function returns a single 'float' and then you return a 'Matrix<2,2>'. Shouldn't your function be:

Matrix<2, 2> matrix(float phi)
{
  Matrix<2, 2> M = {cos(phi), -sin(phi), sin(phi), cos(phi)};
  return M;
}

Thank you

The internet must be really slow where you are, 4 months is a long time, you should change your internet provider and ask for a refund

1 Like

Sorry for late reply. After posting that question, in few days later, I got the solution, and I forgot to look your post.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.