MATLAB: An Array of Equations to solve for 1 variable


I have the following code currently:
L = 3; %Wheelbase in meters%
w = 1.7; %Track in meters%
d = 0.25; %length of nonparallel arm in meters%
B = 14; %Beta: Given value%
I = -30:5:30; %Perameters for inner steering angle%
syms Y
eqn2 = ((sind(B+I))+(sind(B-Y)))==((w/d)-(sqrt((((w/d)-(2.*sin(B))).^2)-(((cosd(B-Y))-(cosd(B+I))).^2))));
sol = solve(eqn2,Y);
I am trying to solve for the 'Y' variable in eqn2 with 'I' changing. The current code is giving me an array of equations all with the variable 'Y' in them but i am not sure on how to solve for those 'Y' values in a way that it will come back an array that I can use to find another variable.

Best Answer

  • There are two solutions for each I value.
    L = sym(3); %Wheelbase in meters%
    w = sym(1.7); %Track in meters%
    d = sym(0.25); %length of nonparallel arm in meters%
    B = sym(14); %Beta: Given value%
    I = sym(-30:5:30); %Perameters for inner steering angle%
    syms Y
    %note correction from sin(B) to sind(B)
    eqn2 = ((sind(B+I))+(sind(B-Y)))==((w/d)-(sqrt((((w/d)-(2.*sind(B))).^2)-(((cosd(B-Y))-(cosd(B+I))).^2))));
    sol_cell = arrayfun(@solve, eqn2, 'uniform', 0);
    sol = horzcat(sol_cell{:});
    If you vpa(sol) then you will see small imaginary quantities in most of the results. My checks show that those are due to round-off, and that the actual values are all real-valued, so you can use real() to discard the imaginary parts.
    Also, simplify(sol,'steps',50) will give you a more compact result.
    And one of the two solutions for eqn2(7) is exactly Y = 0