Embedded Matlab Array Bounds Error

In summary, the conversation discusses a repeated problem with using embedded MATLAB blocks in Simulink, specifically an array out of bounds error when the equations become too long. Potential solutions such as using variable step solvers and breaking up the equations are mentioned, but it is suggested to also check for errors in the equations themselves and consider the data types being used. Further assistance from the Simulink support team is also recommended.
  • #1
aspiers
1
0
Hi,

I keep running into the same problem using the embedded MATLAB blocks of simulink. Once the equations to be solved in my blocks reach a certain length I get an array out of bounds error.

I know Simulink can handle this size of calculation in a timestep as I have much larger equations running in S-Functions in similar models.

Does anyone have any ideas how I can get around this array out of bound problem? (I've already switched to a variable step solver and have tried splitting the equation up into more bite-size chunks).



Code:
function [p1_out,p2_out] = fcn(theta1,theta2)

pq1 = 2*a1*g*cos(theta2)*M2-2*a1*g*cos(theta1)^2*cos(theta2)*M2+a2*g*cos(theta2)^2*M2-2*a2*g*cos(theta1)^2*cos(theta2)^2*M2+M1*a1*g*cos(theta2)-M1*a1*g*cos(theta1)^2*cos(theta2)+sin(theta1)*M1*a1*g*sin(theta2)*cos(theta1)+2*sin(theta1)*a1*g*sin(theta2)*cos(theta1)*M2-sin(theta1)*a1*M2(g*(sin(theta1)*cos(theta2)+cos(theta1)*sin(theta2)))-sin(theta1)*a2*M2(g*(sin(theta1)*cos(theta2)+cos(theta1)*sin(theta2)))*cos(theta2)+2*sin(theta1)*a2*g*sin(theta2)*cos(theta1)*cos(theta2)*M2-a2*M2(g*(sin(theta1)*cos(theta2)+cos(theta1)*sin(theta2)))*sin(theta2)*cos(theta1)+a2*g*cos(theta1)^2*M2

pq2 = 1; % this will be changed to an equation later

p1_out = pq1;
p2_out = pq2;


I know the obvious answer in that the equation is large so no need to remind me of that one ;-)

Many Thanks,

Ad
 
Physics news on Phys.org
  • #2
riana

Hi Adriana,

Thank you for reaching out with your problem. It sounds like you have already tried some potential solutions, such as using a variable step solver and splitting the equation into smaller chunks. These are good approaches, but there may be some other factors at play here as well.

Firstly, it's important to check if there are any errors in your equations themselves. It's possible that there is a mistake or typo that is causing the array out of bounds error. Double check your calculations and make sure everything is correct.

Another potential issue could be with the data types you are using. Make sure that your variables are large enough to handle the calculations you are doing. If you are using double precision, try switching to single precision to see if that helps.

If these steps don't solve the issue, it may be worth reaching out to the Simulink support team for further assistance. They may be able to provide more specific guidance based on your model and equations.

Best of luck with your simulations!




Scientist at [Your Institution]
 
  • #3
rian

Dear Adrian,

I can understand your frustration with encountering an array out of bounds error while using the embedded MATLAB blocks in Simulink. This error occurs when the index used to access an element in an array is outside the allowed range.

There could be several reasons for this error, such as incorrect indexing, incorrect dimensions of the array, or insufficient memory allocation for the array. In your case, it seems like the equations you are trying to solve are too large for the embedded MATLAB blocks to handle. As you have mentioned, the same equations can be solved in S-Functions in similar models, which suggests that the issue may lie with the limitations of the embedded MATLAB blocks.

One possible solution could be to try using a different solver in Simulink, such as the ODE45 solver, which is known to handle larger equations. Another option could be to break down your equations into smaller parts and solve them separately, as you have already tried. You could also try increasing the memory allocation for your arrays, if possible.

If none of these solutions work, you may need to consider using a different software or programming language that can handle larger equations. I hope this helps and wish you the best of luck in finding a solution to your problem.

Sincerely,
 

Related to Embedded Matlab Array Bounds Error

1. What is an "Embedded Matlab Array Bounds Error"?

An "Embedded Matlab Array Bounds Error" occurs when an index used to access an element in an array is outside the bounds of the array. This means that the index is either too large or too small for the size of the array.

2. How does an "Embedded Matlab Array Bounds Error" happen?

An "Embedded Matlab Array Bounds Error" can occur when the wrong index is used to access an element in an array, or when the size of the array is changed without updating the index values.

3. What are the consequences of an "Embedded Matlab Array Bounds Error"?

The consequences of an "Embedded Matlab Array Bounds Error" can vary depending on the specific code and context in which it occurs. In some cases, it may cause the program to crash or produce incorrect results. It can also lead to unexpected and potentially harmful behavior if the incorrect index is used to access important data.

4. How can I prevent an "Embedded Matlab Array Bounds Error"?

To prevent an "Embedded Matlab Array Bounds Error," it is important to carefully check and validate all index values used to access elements in an array. It is also important to update index values if the size of the array is changed. Additionally, using built-in functions and error handling techniques can help catch and prevent these errors.

5. How can I fix an "Embedded Matlab Array Bounds Error"?

To fix an "Embedded Matlab Array Bounds Error," the specific cause of the error must be identified. This may involve debugging the code and checking for incorrect index values or updating index values to match the size of the array. Using built-in functions and error handling techniques can also help in fixing these errors.

Similar threads

Replies
2
Views
626
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Replies
5
Views
951
  • Introductory Physics Homework Help
Replies
19
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
850
  • Advanced Physics Homework Help
Replies
2
Views
3K
  • Programming and Computer Science
Replies
17
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
3K
  • Introductory Physics Homework Help
Replies
5
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
1K
Back
Top