plotting equation which is function of 2 variable

I have one equation in terms of 2 variable A,B, I want to plot magnitude vs phase for different value of A and B .
i don't know how to do this . i was trying but it won't work
for A = -20:1:20
for B = -20:1:20
g=(1+i*B)/(1+i*A);
M=20*log10(abs(g)); %Magnitude matrix of Compensator
M = round(M,2);
P =rad2deg(angle(g)); %Phase Matrix of compensator
P = round(P,2);
plot(P,M);
hold on
end
end
trying to plot this figure
then
Find value of A and B for particualr value of phase and magnitude.

 Accepted Answer

Your code is close. I would take advantage of meshgrid instead of the for loops. Here's what I get making that change. Also, there is no need to round.
[A,B] = meshgrid(-20:1:20);
g=(1+i*B)./(1+i*A);
M=20*log10(abs(g)); %Magnitude matrix of Compensator
P=rad2deg(angle(g)); %Phase Matrix of compensator
plot(P,M,'k')

8 Comments

Looking at your plot, you don't want even spacing in you A & B values. Hard code the values displayed on the plot.
[A,B] = meshgrid([-80 -33 -14 -6 -2.7 -1.2 -0.5 0 .5 1.2 2.7 6 14 33 80]);
g=(1+i*B)./(1+i*A);
M=20*log10(abs(g)); %Magnitude matrix of Compensator
P =rad2deg(angle(g)); %Phase Matrix of compensator
plot(P,M,'k',P,-M,'k')
Thanks @Cris LaPierre
how do reverse that is Finding value of A and B for particualr value of phase and magnitude.
The trick for me was to realize that the lines of B are the negative of the magnitudes of A, so I just plotted +M and -M against phase.
plot(P,M,'k',P,-M,'k')
% (^,^^) ->2nd plot using negative magnitude.
You could compute it if you want using g=(1+i*A)./(1+i*B);
RJS
RJS on 6 Oct 2021
Edited: RJS on 6 Oct 2021
yes @Cris LaPierre but I also want to obtain values of A and B for particular magnitude and phase value .....Consider I have magnitude 10dB and phase 11 deg find value single value of A and B from that chart you have drawn to give magnitude nad phase requirment.
Perhaps try run your equations in reverse?
RJS
RJS on 6 Oct 2021
Edited: RJS on 6 Oct 2021
I am not getting how to do?
syms a b
g=(1+i*b)/(1+i*a)
E = [20*log10(abs(g)) == 10, rad2deg(angle(g)) == 12];
S = solve(E,a,b);
Warning: Unable to find explicit solution. For options, see help.
> In solve (line 317)
empty a and b
Perhaps try adding an assumption that a and b are real.
syms a b real
g=(1+i*b)/(1+i*a);
E = [20*log10(abs(g)) == 10, rad2deg(angle(g)) == 12];
S = vpasolve(E,a,b)
S = struct with fields:
a: 3.1836585625055579563412070062939 b: 10.505085360250508538864040773687
Now test the result to see if it results in the expected M and P values.
A=double(S.a);
B=double(S.b);
g=(1+i*B)./(1+i*A);
M=20*log10(abs(g)) % Should be 10
M = 10.0000
P =rad2deg(angle(g)) % Should be 12
P = 12.0000

Sign in to comment.

More Answers (0)

Asked:

RJS
on 6 Oct 2021

Commented:

RJS
on 9 Oct 2021

Community Treasure Hunt

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

Start Hunting!