Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1.

26 ビュー (過去 30 日間)
% Y asymptote of curve
Rd = 2;
% Release point x
XL = -1;
% Starting point x
X0 = 2.5;
% Find A for launch angles 0-45deg
A_values = ones(1,45);
B_values = ones(1,45);
LaunchAngle = ones(1, 45);
for qL = 1:45
LaunchAngle(1,qL) = qL;
qLrad = deg2rad(qL);
Rd = 2; % Y asymptote of curve
XL = -1; % Release point x
X0 = 2.5; % Starting point x
syms A
syms B
F = [(((-2*A*Rd*exp(A*(XL-B)))/((exp(A*(XL-B))+1)^2))-tan(qLrad)== 0), ((-Rd + ((2*Rd) /(1 + exp(A*(X0 - B))))) == 0)];
AB = vpasolve(F, [A, B])
A_values(1,qL) = AB.A;
B_values(1,qL) = AB.B;
end
I understand i'm currently trying to store the incorrect number of elements but I'm new to MATLAB and don't see how I'm doing this.
Offending line is:
A_values(1,qL) = AB.A;

採用された回答

Star Strider
Star Strider 2020 年 3 月 11 日
The problem is that vpasolve could not find a solution, so it returned an empty vector. The Symbolic Math Toolbox is good for many things although not for iterative calculations.
Try this instead:
for qL = 1:45
LaunchAngle(1,qL) = qL;
qLrad = deg2rad(qL);
Rd = 2; % Y asymptote of curve
XL = -1; % Release point x
X0 = 2.5; % Starting point x
% syms A
% syms B
F = @(A,B) [(((-2*A*Rd*exp(A*(XL-B)))/((exp(A*(XL-B))+1)^2))-tan(qLrad)), ((-Rd + ((2*Rd) /(1 + exp(A*(X0 - B))))))];
AB0 = [1; 1];
AB = fsolve(@(b)F(b(1),b(2)), AB0)
A_values(:,qL) = AB(1);
B_values(:,qL) = AB(2);
end
Experiment with the initial parameter estimates (‘AB0’) if necessary to get different results.
  6 件のコメント
Adam Thompson
Adam Thompson 2020 年 3 月 12 日
apologies, typo my end. Thanks for your help star strider
Star Strider
Star Strider 2020 年 3 月 12 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by