fsolve error: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I’m tring to run the following set of code:
%% SW Model: Primary VR
dfreq_SW_vr = -6e-3;
% MMS
gamma_SW = 0.0001*pi : 0.0001 : 0.415*pi;
x0_SW = [0, 0];
options = optimoptions(@fsolve,’StepTolerance’,1e-15);
for ct = 1:numel(gamma_SW)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
x0_SW = [ x_SW(end,1)+0.001 , x_SW(end,2)+0.003]; % Update IC
end
figure(8)
% MMS (Stable)
plot(x_SW(1:10,1), 2*x_SW(1:10,2),’Color’,[.7 .7 .7],’LineWidth’,2.5)
hold on; grid on;
%% Function File (SW VR)
function Eqn_SW = bicycle_SW(x_SW, gamma_SW)
global w b g1 g2 g3 g4 dfreq_SW_vr nu f1b f2b zet_0_0 eta_0_0 zet_1_0 eta_1_0 zet_2_0 eta_2_0 zet_3_0 eta_3_0
% Note: Eqn(1) = Real, Eqn(2) = Imag
% Note: x_–(1) = d, x_–(2) = a
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 + ((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) + ((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Eqn_SW(2) = (-1./2).*b.*w(1).*x_SW(2).*g2 + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*sin(gamma_SW) + ((1./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*sin(gamma_SW);
end
But I get the following error when I run it:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in untitled3>bicycle_SW (line 91)
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 +
f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 +
((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) +
((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Error in untitled3>@(x_SW)bicycle_SW(x_SW,gamma_SW(ct)) (line 13)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
Not sure what I’m doing wrong… Any help would be much appreciated.I’m tring to run the following set of code:
%% SW Model: Primary VR
dfreq_SW_vr = -6e-3;
% MMS
gamma_SW = 0.0001*pi : 0.0001 : 0.415*pi;
x0_SW = [0, 0];
options = optimoptions(@fsolve,’StepTolerance’,1e-15);
for ct = 1:numel(gamma_SW)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
x0_SW = [ x_SW(end,1)+0.001 , x_SW(end,2)+0.003]; % Update IC
end
figure(8)
% MMS (Stable)
plot(x_SW(1:10,1), 2*x_SW(1:10,2),’Color’,[.7 .7 .7],’LineWidth’,2.5)
hold on; grid on;
%% Function File (SW VR)
function Eqn_SW = bicycle_SW(x_SW, gamma_SW)
global w b g1 g2 g3 g4 dfreq_SW_vr nu f1b f2b zet_0_0 eta_0_0 zet_1_0 eta_1_0 zet_2_0 eta_2_0 zet_3_0 eta_3_0
% Note: Eqn(1) = Real, Eqn(2) = Imag
% Note: x_–(1) = d, x_–(2) = a
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 + ((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) + ((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Eqn_SW(2) = (-1./2).*b.*w(1).*x_SW(2).*g2 + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*sin(gamma_SW) + ((1./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*sin(gamma_SW);
end
But I get the following error when I run it:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in untitled3>bicycle_SW (line 91)
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 +
f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 +
((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) +
((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Error in untitled3>@(x_SW)bicycle_SW(x_SW,gamma_SW(ct)) (line 13)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
Not sure what I’m doing wrong… Any help would be much appreciated. I’m tring to run the following set of code:
%% SW Model: Primary VR
dfreq_SW_vr = -6e-3;
% MMS
gamma_SW = 0.0001*pi : 0.0001 : 0.415*pi;
x0_SW = [0, 0];
options = optimoptions(@fsolve,’StepTolerance’,1e-15);
for ct = 1:numel(gamma_SW)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
x0_SW = [ x_SW(end,1)+0.001 , x_SW(end,2)+0.003]; % Update IC
end
figure(8)
% MMS (Stable)
plot(x_SW(1:10,1), 2*x_SW(1:10,2),’Color’,[.7 .7 .7],’LineWidth’,2.5)
hold on; grid on;
%% Function File (SW VR)
function Eqn_SW = bicycle_SW(x_SW, gamma_SW)
global w b g1 g2 g3 g4 dfreq_SW_vr nu f1b f2b zet_0_0 eta_0_0 zet_1_0 eta_1_0 zet_2_0 eta_2_0 zet_3_0 eta_3_0
% Note: Eqn(1) = Real, Eqn(2) = Imag
% Note: x_–(1) = d, x_–(2) = a
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 + ((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) + ((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Eqn_SW(2) = (-1./2).*b.*w(1).*x_SW(2).*g2 + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*sin(gamma_SW) + ((1./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*sin(gamma_SW);
end
But I get the following error when I run it:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in untitled3>bicycle_SW (line 91)
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 +
f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 +
((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) +
((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Error in untitled3>@(x_SW)bicycle_SW(x_SW,gamma_SW(ct)) (line 13)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
Not sure what I’m doing wrong… Any help would be much appreciated. fsolve, compatible, indices MATLAB Answers — New Questions