Hi,(adsbygoogle = window.adsbygoogle || []).push({});

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 (Text):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 Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Embedded Matlab Array Bounds Error

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads for Embedded Matlab Array | Date |
---|---|

MATLAB MATLAB: forces acting on an object | Apr 6, 2018 |

MATLAB Matlab histogram | Apr 4, 2018 |

MATLAB Sovling Bernoulli's differential equation in matlab? | Apr 3, 2018 |

MATLAB Matlab-like software | Mar 27, 2018 |

Embedding Latex in HTML | Mar 23, 2010 |

**Physics Forums - The Fusion of Science and Community**