Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Embedded Matlab Array Bounds Error

  1. Oct 6, 2008 #1

    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,

  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Discussions: Embedded Matlab Array Bounds Error
  1. Matlab and arrays (Replies: 0)

  2. Matlab Error (Replies: 1)

  3. Arrays in MATLAB (Replies: 3)