What are the possible reasons for data jumps in the plot?
조회 수: 4 (최근 30일)
이전 댓글 표시
What might be the cause of such numerical instability and how can it be solved? Note: Expected plot should be as like "Green" color.
A0 = 1.5207;
A1 = 0.853721-1.816893i;
A2 = 1;
th = 0:0.5:90;
th0 = th*pi/180; % deg to rad
c0 = cos(th0);
th1 = asin((A0/A1).*sin(th0));
c1 = cos(th1);
th2 = asin((A1/A2).*sin(th1));
c2 = cos(th2);
b = 2.*pi.*50.*A1.*c1./500;
M1 = (A1.*c0 - A0.*c1)./(A1.*c0 + A0.*c1);
M2 = (A2.*c1 - A1.*c2)./(A2.*c1 + A1.*c2);
M = (M1 + (M2.*exp(-2i.*b)))./(1+(M1.*M2.*exp(-2i.*b)));
P = abs(M).^2;
plot(th, P), grid, xlabel \theta, ylabel P
댓글 수: 3
Image Analyst
2024년 5월 18일
Yeah @John D'Errico I think the Crystal Ball Toolbox is the wrong one here. I think you need the Mind Reading Toolbox. Unfortunately it's not released yet and only @Walter Roberson has an early alpha release of it.
채택된 답변
Walter Roberson
2024년 5월 19일
이동: Walter Roberson
2024년 5월 19일
Q = @(v) sym(v);
Pi = Q(pi);
A0 = Q(15207)/Q(10)^4;
A1 = Q(0853721)/Q(10)^6-Q(1816893)/Q(10)^6*1i;
A2 = Q(1);
th = Q(0:0.5:90);
th0 = th*Pi/180; % deg to rad
c0 = cos(th0);
th1 = asin((A0/A1).*sin(th0));
c1 = cos(th1);
th2 = asin((A1/A2).*sin(th1));
c2 = cos(th2);
b = 2.*Pi.*50.*A1.*c1./500;
M1 = (A1.*c0 - A0.*c1)./(A1.*c0 + A0.*c1);
M2 = (A2.*c1 - A1.*c2)./(A2.*c1 + A1.*c2);
M = (M1 + (M2.*exp(-2i.*b)))./(1+(M1.*M2.*exp(-2i.*b)));
P = abs(M).^2;
plot(th, P), grid, xlabel \theta, ylabel P
댓글 수: 8
Paul
2024년 5월 21일
Well, I guess it really wan't my solution insofar as I didn't get it to work. Maybe @Walter Roberson did something else that I missed
I see that using those single quotes defining A0 and A1 can make a small difference
Q = @(v) sym(v);
Q('1.5207') - Q(1.5207)
Q('0.853721 - 1.816893i') - Q(0.853721 - 1.816893i)
Is that the reason this solution covers the lower part of the envelope and Walter's covers the upper part? Seems very sensitive.
Another approach is to form P entirely symbolically, and the substitute the nuerical constants at the end, which sometimes takes advantage of opportunities to simplify expressions that might not otherwise be seen with a bunch of VPA numbers floating around.
Pi = Q(pi);
syms A0 A1
% A0 = Q(15207)/Q(10)^4;
% A1 = Q(0853721)/Q(10)^6 - Q(1816893)/Q(10)^6*1i; % 0.853721 - 1.816893i;
%A0 = Q('1.5207');
%A1 = Q('0.853721 - 1.816893i');
A2 = Q(1);
th = Q(0:0.5:90);
%th0 = th*Pi/180; % deg to rad
syms th0
c0 = cos(th0);
th1 = asin((A0/A1).*sin(th0));
c1 = cos(th1);
th2 = asin((A1/A2).*sin(th1));
c2 = cos(th2);
b = 2.*Pi.*50.*A1.*c1./Q(500);
M1 = (A1.*c0 - A0.*c1)./(A1.*c0 + A0.*c1);
M2 = (A2.*c1 - A1.*c2)./(A2.*c1 + A1.*c2);
M = (M1 + (M2.*exp(-2i.*b)))./(1+(M1.*M2.*exp(-2i.*b)));
M = simplify(M);
P = abs(M).^2;
P = subs(P,[A0 A1],[Q('1.5207'), Q('0.853721 - 1.816893i')]);
symvar(P)
P = subs(P,th0,th*Pi/180);
plot(th, P, 'color', '#AAE2A8', 'linewidth', 3), grid, xlabel \theta, ylabel P, grid
And now we have a different result (I don't know why the grid command doesn't work).
추가 답변 (1개)
Image Analyst
2024년 5월 19일
I don't know where those equations come from. Is it some kind of chaos theory? Anyway, to plot in green like you asked, you need to use 'g-'
plot(th, P, 'g-');
댓글 수: 11
참고 항목
카테고리
Help Center 및 File Exchange에서 Detection에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!