linspace is causing an error
古いコメントを表示
My goal is to plot R, where R=1-T
T is a function of n2 and D, where n2 takes the values
n2 = [1.2 1.75 2.2] and D = linspace(0,1) and the function of T is equal to:
T = 

So my code so far is *note(lambda = 1):
n2 = [1.2 1.75 2.2];
D = linspace(0,1);
T= (9.68.*n2.^2)./(11.6964.*n2.^2)+(1-n2.^2).*(5.8564-n2.^2).*(sin((2*pi*D)./1)).^2
>>Arrays have incompatible sizes for this operation.<<
I think what is happening is D which is 1x100 matrix is making this incompatible.
My end goal is to plot this and end up with 3 graphs, where one graph represents a value of n2 going through all of D.
I am very inexperienced at matlab but im trying to figure this out. Any help?
5 件のコメント
Steven Lord
2022 年 10 月 12 日
Snow
2022 年 10 月 12 日
Image Analyst
2022 年 10 月 12 日
To clarify, do you want three line plots in a single axes (like @VBBV's answer below)? Or do you want one line plot in three different axes (like my answer below)?
Snow
2022 年 10 月 12 日
dpb
2022 年 10 月 12 日
NOTA BENE:
The equation for T used by both @Image Analyst and @VBBV is the same as that originally posted that has a transcription error in not including all the additive terms in the denominator.
See the later Answer I posted that corrects the equation-- the result is much different.
"There be dragons!"
採用された回答
その他の回答 (2 件)
n2 = [1.2 1.75 2.2];
D = linspace(0,1,100);
for k = 1:length(D)
T(:,k)= (9.68.*n2.^2)./(11.6964.*n2.^2)+(1-n2.^2).*(5.8564-n2.^2).*(sin((2*pi*D(k))./1)).^2;
end
plot(D,T)
It's because n2 and D are different sizes so you can't do it all in one equation. Try a loop
all_n = [1.2 1.75 2.2];
D = linspace(0,1);
whos all_n
whos D
for k = 1 : length(all_n)
% Get this one value of n
n2 = all_n(k);
% Compute T
T = (9.68.*n2.^2)./(11.6964.*n2.^2)+(1-n2.^2).*(5.8564-n2.^2).*(sin((2*pi*D)./1)).^2;
% Plot the curve
subplot(3, 1, k);
plot(D, T, 'b-', 'LineWidth', 2)
grid on
xlabel('D');
ylabel('T')
caption = sprintf('n2 = %.2f', n2);
title(caption);
fontsize(gca, 12, 'points')
end
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


