0

Hello guys,

I'm trying to plot the following two simultaneous equations within the same plot:

eq1: IDS1 :==: KN * (VGS - VTH - VDS/2)*VDS ;
eq2: IDS1 :==: (VDD - VDS)/RD;

The thing is: I already have the corresponding Values for VDS and IDS as you can see it below on my code, what I just want to do is plot them, I've been working in Mathematica for a while but only with symbolic calculus.

I've solved this problem analytically, but I want to add the graph as well, and include it on the final notebook.

Unfortunately I don't get it how to properly plot the solution(I've been trying in so ways without any luck). Also, I've solve it on Matlab, but I don't get it out how to do it on Mathematica, and I really want to do it with Mathematica.

I hope you could help me. BTW: Here's how I do It with Matlab(the graph) and my Actual Notebook on Mathematica: Actual Code

ClearAll["Global`*"]
VDD = 10;
VTH = 4;
VGS = 5;
KN   = 1.173;
RD   = 100;
VDS = Range[0, 6, 0.01];(*Equivalent to var=[0:0.001:2] in matlab*)

IDS1 = KN * (VGS - VTH - VDS/2)*VDS ; IDS2 = (VDD - VDS)/RD;

Plot[{{IDS1}, {IDS2}}, {VDS, 0, 10}, AxesLabel -> {"VDS(V)", "IDS(mA)"}, PlotLegends -> Automatic]

ClearAll["Global`*"] VDD = 10; VTH = 4; VGS = 5; KN = 1.173; RD = 100;

eq1 = KN * (VGS - VTH - VDS/2)VDS - IDS1 == 0;(Used only when transistor is used as
switch: I.O.:Q Working in Triode/Ohmic Region *)

eq2 = (VDD - VDS)/RD - IDS1 == 0; (Comes from applying KVL to Drain-Source Loop) N[EngineeringForm[Solve[{ eq1, eq2}, {VDS, IDS1}]]]

2 Answers2

1

Amplifying on answer by Jagra

ClearAll["Global`*"]

VDD = 10; VTH = 4; VGS = 5; KN = 1.173; RD = 100; VDS = Range[0, 6, 0.01];

IDS1 = KN(VGS - VTH - VDS/2)VDS;

IDS2 = (VDD - VDS)/RD;

IDS1 and IDS2 are lists, not functions. Use ListLinePlot rather than Plot. Also, since their scales are radically different use ResourceFunction["CombinePlots"]

ResourceFunction["CombinePlots"][
 ListLinePlot[IDS1,
  Frame -> True,
  FrameStyle -> ColorData[97][1],
  PlotStyle -> ColorData[97][1],
  DataRange -> {0, 6}],
 ListLinePlot[IDS2,
  Frame -> True,
  FrameStyle -> ColorData[97][2],
  PlotStyle -> ColorData[97][2],
  DataRange -> {0, 6}],
 "AxesSides" -> "TwoY",
 FrameLabel -> {{"IDS1(mA)", "IDS2(mA)"}, {Style["VDS(V)", Black], None}}]

enter image description here

EDIT:

Clear[VDS, IDS1]

KN = 1.173 // Rationalize;

eq1 = KN(VGS - VTH - VDS/2)VDS - IDS1 == 0;

eq2 = (VDD - VDS)/RD - IDS1 == 0;

(sol = Solve[{eq1, eq2}, {VDS, IDS1}]) // N // EngineeringForm[#, {6, 2}] &

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • Thanks @Bob Hanlon for answering, unfortunately, I don't have the latest version of Mathematica, the one I'm using it's quite old, but I've spinned out your code, in order to use it with the version I have, and here's the results:

    Link

    – hector gonzalez Jul 13 '21 at 07:07
  • For older versions look at older Q&A on this site, e.g., link – Bob Hanlon Jul 13 '21 at 12:17
0

I think you've made things more complicated than you need to.

Does the following give you something closer to what you want?

VDD = 10;
VTH = 4;
VGS = 5;
KN = 1.173;
RD = 100;
VDS = Range[0, 6, 0.01];
IDS1 = KN*(VGS - VTH - VDS/2)*VDS;
IDS2 = (VDD - VDS)/RD;

ListLinePlot[{IDS1, IDS2}, AxesLabel -> {"VDS(V)", "IDS(mA)"}, PlotLegends -> Automatic, AspectRatio -> 1/3, ImageSize->400]

enter image description here

You've already created two lists of the data you need to display. ListLinePlot gives you what you need.


I haven't had a chance to study your second bit of code:

VDD = 10;
VTH = 4;
VGS = 5;
KN   = 1.173;
RD   = 100;

eq1 = KN * (VGS - VTH - VDS/2)VDS - IDS1 == 0; (Used only when transistor is used as switch: I.O.:Q Working in Triode/Ohmic Region *)

eq2 = (VDD - VDS)/RD - IDS1 == 0; (Comes from applying KVL to Drain-Source Loop)

N[EngineeringForm[Solve[{eq1, eq2}, {VDS, IDS1}]]]

Review Solve in the documentation. On first look your's doesn't look set up right.

I'll come back to this later, but I suspect you'll get an answer or two in the meantime.

Jagra
  • 14,343
  • 1
  • 39
  • 81