Вы находитесь на странице: 1из 7

NDSU

3: SciLab

ECE 321 - JSG

SciLab, MATLAB, and MultiSim


SciLab & MATLAB
SciLab and MATLAB are very similar programs. They both turn a PC into a calculator which can manipulate
matricies, handle complex numbers, and plot the results. MATLAB is the official language of ECE. SciLab is
very similar to MATLAB and is free (!). We'll be using SciLab throughout this semester. If you use Matlab, the
syntax presented in these lecture notes should also work.
VisSim is similar to Matlab's Simulink. It is a graphical tool that lets you solve differential equations, such as
finding the voltages in a circuit with capacitors. More on this shortly.
Some of the things we'll be doing with SciLab this semester is
Plotting functions
Solving 2 equations for 2 unknowns, and
Doing calculus.

Plotting Functions in SciLab & MATLAB:


The syntax in SciLab is as follows:
[
start of a matrix
]
end of a matrix
,
next column
;
next row within a matrix, don't display the results at the end of a line
'
transpose
plot(x,y) plot x vs. y
For example, plot the function

y = 3 + 4 sin (10t) + 2 cos (50t)


In SciLab:
t = [0:0.01:3]';
y = 3+4*sin(10*t)+2*cos(50*t);
plot(t,y);
xlabel('seconds');
ylabel('y');
xgrid(5)

Next, find the derivative and integral of y(t). The derivative is


dy
dt

dy
.
dt

Numerically,

y(i)y(i1)
t(i)t(i1)
1

August 24, 2012

NDSU

3: SciLab

ECE 321 - JSG

or
-->size(y)
301.

1.

-->dy = 0*y;
-->for i=2:300
-->
dy(i) = (y(i+1) - y(i-1)) / 0.02;
-->
end
-->plot(t,dy)

Note that differentiation amplifies the high-frequency terms. The 50 rad/sec term dominates the result.
The integral is
t

0 y dt y(i) dt
t

i=0

in SciLab
-->iY = 0*y;
-->for i=2:301
-->
iY(i) = iY(i-1) + y(i)*0.01;
-->
end
-->plot(t,iY)

Note that integration amplifies the low-frequency terms. The resulting signal is dominated by a ramp: the
integral of a constant is a ramp.
2

August 24, 2012

NDSU

3: SciLab

ECE 321 - JSG

You can also use SciLab to solve for 2 equations and 2 unknowns. For example, when we get to diodes, we'll try
to solve the following two equations for V and I:

V=5I
V = 0.0526 ln (10 5 I + 1)
In SciLab
-->I = [0:0.01:5]';
-->V1 = 5-I;
-->V2 = 0.0526*log(1e5*I+1);
-->plot(V1,I,V2,I);
-->xlabel('Volts');
-->xgrid(5)
-->ylabel('mA');

The solution from the graph is where the two graphs interesect. You can also find this numerically.
Guess I.
Find V from equation 1 and 2
Find the difference in V. This gives a function of I whose solution is when f(I)=0.
Use a solver (such as Newton's method) to find I:
The results is (0.6825V, 4.3175mA)

Frequency Response in SciLab:


SciLab also works for complex numbers. For example, find the amplitude of G(s) from 0 to 10 Hz:

G(s) =
-->f
-->w
-->j
-->s
-->G

=
=
=
=
=

5s
s 2 +5s+100

[0:0.01:10]';
2*%pi*f;
sqrt(-1);
j*w;
5*s ./ (s.^2 + 5*s + 100);

-->plot(f,abs(G))
-->xlabel('Hz');
-->ylabel('gain');

August 24, 2012

NDSU

3: SciLab

ECE 321 - JSG

Adding a function in MATLAB:


Create a file and give it an extension of .m. (for example, call the funciton jake.m ). When you type in the word
jake
Matlab uses the variable with the name of jake. If this doesn't exist,
Matlab looks for the file with the name jake.m in the current directory and executes it. If this doesn't exist,
Matlab looks in the default directory. If still no file is found,
Matlab gives you an error.

Adding a function in SciLab:


Adding a funciton in Scilab is a little harder. Suppose you want to add a function 'dB' which is called as
y = dB(x)
In SciLab, go to File Change Current Directory. Change it to where your files are located.

Go to File Open a file. Open up a .sci file. Change it as follows:

August 24, 2012

NDSU

3: SciLab

ECE 321 - JSG

note: SciLab is very picky.


The file name must patch the function name
Both are case sensitive
Once you have a file you're happy with, add this to SciLab (execute - load into Scilab)

note: If you create a bunch of files, you can load them into Scilab one at a time. Save the environment. When
you restart Scilab, load the environment and all the functions that were in Scilab before are there again.

August 24, 2012

NDSU

3: SciLab

ECE 321 - JSG

MultiSim
MultiSim is available on the cluster computers. It allows you to run nonlinear numerical simulations of circuits.
Typically, each homework set should include:
Analysis: Using simplifying approximations (such as the voltage across a diode is 0.7V and there is no
resistance), calculate values for resistors and compute what the currents and voltages should be.
Simulation: Using MultiSim, check your answers with a more complex (and more accurate, but still
impefect) tool
Hardware: Determine the actual currents, voltages etc. with real components.
All results should be similar - but slightly different due to the simplifying approximations used.

For example, determine the voltage at y(t) for x(t) being a 5Vp 1kHz sine wave with Multi-Sim.
R1
I0
+
x(t)

I1

I2

C
R2

y(t)

In MultiSim,
Add the components using the drop-down menu bars on the top
Connect components using click and drag
Add a multimeter or oscilloscope from the menu on the right
Click the on-off switch
For print-outs, reverse the image of the o-scope
The net result will look like the following:

August 24, 2012

NDSU

3: SciLab

ECE 321 - JSG

What this tells you is:


The DC value (average) output voltage is 4.152 volts
The output has some ripple - as shown on the oscilloscope
If you switch the volt meter to AC, the ripple is 0.113V rms.
Presumably, you could calculate these numbers as well as measure these with hardware for comparison.

August 24, 2012

Вам также может понравиться