Issue while plotting the equation

Vfb=1.2;
phit=0.026;
Nd=1e19;
ni=1.5e10;
q=1.6e-19;
Tsc=10^-6;
tox=0.8*10^-7
W=10^-4
L=10^-4
eox=25*8.8*1e-14
esi=8.8*11.7*1e-14
Cox=eox/tox
Ld=sqrt((esi*phit)/(q*Nd))
gamma=(sqrt(2*q*Nd*esi))/(Cox)
mu=100
mub=200
d=4*Cox^2*gamma^2*phit
p=q*Nd*Tsc
a=0.001
Vds=0.01
tf=12*10^-7;
Qs=2.7*10^-5
Qc=2*10^-5
Ec=10^6
f=2*esi*3.14*0.026*q*q*Nd*Nd*Tsc;
alpha_0=(((3*(Qs^4)*(Qc^2))-(5*(Qc^4)*(Qs^2)))/((4*(Qs^2)*(Qc^5))-(2*(Qs^4)*(Qc^3))-(2*Qc^7)))*Ec
beeta_0=(((5*Qc^4)-Qs^4)/((4*(Qs^2)*(Qc^5))-(2*(Qs^4)*(Qc^3))-(2*Qc^7)))*Ec
damma_0=(((Qs^2)-3*Qc^2)/((4*(Qs^2)*(Qc^5))-(2*(Qs^4)*(Qc^3))-(2*Qc^7)))*Ec
alpha=2*tf*alpha_0
beeta=4*tf*beeta_0
damma=6*tf*damma_0
N=500;
Vgd=linspace(0,1.2,N);
Vgs=linspace(0,1.2,N);
Qd=zeros(1,N);
Qs=zeros(1,N);
Ids=zeros(1,N);
for i=1:500
syms x
eqnLeft = Vgd(i)-Vfb-Vds+((Tsc/(8*esi))*(x+p));
eqnRight =0.026*(log(2*sqrt(((x+p)*Tsc)/(8*3.14*0.026*esi))*(1-((x+p)/(p)))))+((alpha+(1/Cox))*((x+p)/2))+(beeta*(((x+p)/2).^3))+(damma*(((x+p)/2).^5));
Qd(1,i)=vpasolve(eqnLeft == eqnRight,x,10^-11);
end
for i=1:500
syms x
eqnLeft = Vgs(i)-Vfb+((Tsc/(8*esi))*(x+p));
eqnRight =0.026*(log(2*sqrt(((x+p)*Tsc)/(8*3.14*0.026*esi))*(1-((x+p)/(p)))))+((alpha+(1/Cox))*((x+p)/2))+(beeta*(((x+p)/2).^3))+(damma*(((x+p)/2).^5));
Qs(1,i)=vpasolve(eqnLeft == eqnRight,x,10^-11);
end
hold on
plot(Vgd,abs(Qd))
plot(Vgs,abs(Qs))
hold off
While plotting Qd and Qs I am getting its complex values in workspace, how can i just plot the real values??

Risposte (3)

z = 3+1i*2
z = 3.0000 + 2.0000i
real(z)
ans = 3
imag(z)
ans = 2

2 Commenti

Not like that i mean there will be 5 roots since it is 5th order eqtn then how can i just take real root amongst 5 of the root
If A is your vector of both real and complex numbers, to extract only real numbers use:
A_real = A(imag(A) == 0)

Accedi per commentare.

Mohd Ayaz
Mohd Ayaz il 12 Dic 2021

0 voti

Actually if you look at the code then x should have 5 roots but it's just storing 1 complex root in Qd or Qs but i want to store real root amongst all 5 roots is there any method with which i can do this?

2 Commenti

KSSV showed you how: A_real = A(imag(A) == 0) where A is the name of the variable that has all of the roots.
But how to get variable A which has all roots ? I mean by my method I am only able to get 1 root

Accedi per commentare.

Vfb=1.2;
phit=0.026;
Nd=1e19;
ni=1.5e10;
q=1.6e-19;
Tsc=10^-6;
tox=0.8*10^-7;
W=10^-4;
L=10^-4;
eox=25*8.8*1e-14;
esi=8.8*11.7*1e-14;
Cox=eox/tox;
Ld=sqrt((esi*phit)/(q*Nd));
gamma=(sqrt(2*q*Nd*esi))/(Cox);
mu=100;
mub=200;
d=4*Cox^2*gamma^2*phit;
p=q*Nd*Tsc;
a=0.001;
Vds=0.01;
tf=12*10^-7;
Qs=2.7*10^-5;
Qc=2*10^-5;
Ec=10^6;
f=2*esi*3.14*0.026*q*q*Nd*Nd*Tsc;
alpha_0=(((3*(Qs^4)*(Qc^2))-(5*(Qc^4)*(Qs^2)))/((4*(Qs^2)*(Qc^5))-(2*(Qs^4)*(Qc^3))-(2*Qc^7)))*Ec;
beeta_0=(((5*Qc^4)-Qs^4)/((4*(Qs^2)*(Qc^5))-(2*(Qs^4)*(Qc^3))-(2*Qc^7)))*Ec;
damma_0=(((Qs^2)-3*Qc^2)/((4*(Qs^2)*(Qc^5))-(2*(Qs^4)*(Qc^3))-(2*Qc^7)))*Ec;
alpha=2*tf*alpha_0;
beeta=4*tf*beeta_0;
damma=6*tf*damma_0;
N=5;
Vgd=linspace(0,1.2,N);
Vgs=linspace(0,1.2,N);
%Qd=zeros(1,N);
%Qs=zeros(1,N);
Ids=zeros(1,N);
for i=1:N
syms x
eqnLeft = Vgd(i)-Vfb-Vds+((Tsc/(8*esi))*(x+p));
eqnRight =0.026*(log(2*sqrt(((x+p)*Tsc)/(8*3.14*0.026*esi))*(1-((x+p)/(p)))))+((alpha+(1/Cox))*((x+p)/2))+(beeta*(((x+p)/2).^3))+(damma*(((x+p)/2).^5));
Qd{i} = solve(eqnLeft == eqnRight, x, 'real', true);
end
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
for i=1:N
syms x
eqnLeft = Vgs(i)-Vfb+((Tsc/(8*esi))*(x+p));
eqnRight =0.026*(log(2*sqrt(((x+p)*Tsc)/(8*3.14*0.026*esi))*(1-((x+p)/(p)))))+((alpha+(1/Cox))*((x+p)/2))+(beeta*(((x+p)/2).^3))+(damma*(((x+p)/2).^5));
Qss{i} = solve(eqnLeft == eqnRight, x, 'real', true);
end
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
Warning: Unable to find explicit solution. For options, see help.
%{
hold on
plot(Vgd,abs(Qd))
plot(Vgs,abs(Qs))
hold off
%}
Qd{1}
ans = Empty sym: 0-by-1
Qss{1}
ans = Empty sym: 0-by-1
residue = eqnLeft - eqnRight
residue = 
string(residue)
ans = "(38759912637870261*x)/274877906944 - (13*log(-(9444732965739290427392*x*((38685626227668133590597632*x)/26014240345388328125 + 61897001964269002752/26014240345388328125)^(1/2))/7555786372591431))/500 + (5954689997320791*(x/2 + 7555786372591431/9444732965739290427392)^3)/8 - 1958130468122061235552256*(x/2 + 7555786372591431/9444732965739290427392)^5 + 292861619712054503059211338333491/1298074214633706907132624082305024"
%fplot([real(residue), imag(residue)], [-1 1])

1 Commento

There are NO real-roots of that residue expression, which is the 5th Qss output.
Look at the square root: that has to be positive or else te sqrt() will be imaginary. But you need a negative x so that the -x*sqrt() gives a positive number. So you need x to be between solve() of the expression under the square root, and 0. But if you graph residue over that range you can see that it never crosses zero there.
You are incorrect that there are 5 roots. There is an (x+c)^5 term, but there is also that log(sqrt()) term.
So, your problem cannot be solved.

Accedi per commentare.

Categorie

Tag

Richiesto:

il 12 Dic 2021

Commentato:

il 12 Dic 2021

Community Treasure Hunt

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

Start Hunting!

Translated by