Solving Simultaneous Equations with FreeMat
Here we use FreeMat to solve a system of equations that arise from using KVL and KCL on the circuit above. It is given that V1 = 15V , V2 = 7V , R1 = 20Ω , R2 = 5Ω, R3=10Ω. We are looking for the current through R3.
Let node A be the node at the top, over the R3 resistor. We choose currents I1 and I2 at the top and pointing to the left, that is I1 is coming out of node A and I2 is coming into the node. I3 is chosen to go through R3 and points up, going into node A. KCL gives us the equation I1 - I2 + I3. Using KVL at the two independent loops, we obtain two equations: 15 + 20I1 + 10I3 = 0 and 7 - 10I3 + 5I2 = 0. Using the KCL equation, we can write the KVL equations in terms of only two currents I2 and I3. We get 20I2 + 30I3 = -15 and 5I2 -10I3 = -7.
Using FreeMat, we can set the resistances in a matrix R and the voltages in a matrix V. Now we can perform matrix multiplication, multiplying the inverse of matrix R with matrix V to find the current matrix I: I = inv(R)*V. This gives us our current vector I = [I2 , I3] = [-1.0286,0.1857]. So the current through the R3 resistor is I3 = 0.1857 Ω in the direction pointing up towards node A.
Plotting Exponentials
Here we plot the graphs of output vs. time of two circuits, Circuit A and Circuit B. The output is given as 2*exp(-t/τ). The time constants for Circuit A and Circuit B are τ = 100 ms and τ = 200 ms, respectively. We need to find which circuit will reach the lowest output soonest.
First the time vector, t, was set using the linspace command. A start point of 0 and endpoint of 1 was chosen (in seconds) with a 1000 points in between. Next the time constant variables tau1 and tau2 were created. The output vectors for each circuit were created (circuitA and circuitB) using the output equation given. Next the plot command was used along with the legend command to help distinguish the two curves.
We see that the blue curve reaches the lowest output first. From the legend, the blue curve represents the circuit with the 100 ms time constant, Circuit A. Next time a more appropriate name such as Circuit A will be given for clarity.
We now plot the ouput vs. time graphs for the same circuits, using the same time constants. This time however the output equation has changed to 2*(1-exp(-t/τ)).
The time constant variables remained unchanged, only the circuit variables were updated (circuitA, circuitB). The plot was created the same was as the first time. This time, the legend was improved as planned, and axis labels were created.
We can see that the output of Circuit A reaches 2 faster than Circuit B.
First the time vector, t, was set using the linspace command. A start point of 0 and endpoint of 1 was chosen (in seconds) with a 1000 points in between. Next the time constant variables tau1 and tau2 were created. The output vectors for each circuit were created (circuitA and circuitB) using the output equation given. Next the plot command was used along with the legend command to help distinguish the two curves.
We see that the blue curve reaches the lowest output first. From the legend, the blue curve represents the circuit with the 100 ms time constant, Circuit A. Next time a more appropriate name such as Circuit A will be given for clarity.
We now plot the ouput vs. time graphs for the same circuits, using the same time constants. This time however the output equation has changed to 2*(1-exp(-t/τ)).
The time constant variables remained unchanged, only the circuit variables were updated (circuitA, circuitB). The plot was created the same was as the first time. This time, the legend was improved as planned, and axis labels were created.
We can see that the output of Circuit A reaches 2 faster than Circuit B.
Using FreeMat we add two sinusoidal functions. We then plot the individual functions as well as the curve representing the addition of the functions on the same plot. The equations are 3*sin(2t+10°) and 5*cos(2t-30°).
A sinusoidal function has the form of A*sin(ωt+θ) where A is the amplitude, ω is the frequency, t is time, and θ is the phase angle.
First, a frequency variable, omega, is set equal to 2 since it is the same in both equations. Next a time vector t, is created using linspace command going from 0 to 2π/ω with 500 plot points. A conver variable is created to convert degrees to radians since degrees must not be used in sinusoidal functions in FreeMat. Next, phase variables are created, phase1 and phase2 which are the phase angles θ for the two equations. Finally variables are created for the two equations, including their respective amplitudes, function types (sin or cosine), frequencies, and phase angle (converted to degrees by multiplying the conver variable). Now an output variable is created as the summation of the curve variables just mentioned. We now use the plot command to plot all three curves on the same graph as shown above.
First, a frequency variable, omega, is set equal to 2 since it is the same in both equations. Next a time vector t, is created using linspace command going from 0 to 2π/ω with 500 plot points. A conver variable is created to convert degrees to radians since degrees must not be used in sinusoidal functions in FreeMat. Next, phase variables are created, phase1 and phase2 which are the phase angles θ for the two equations. Finally variables are created for the two equations, including their respective amplitudes, function types (sin or cosine), frequencies, and phase angle (converted to degrees by multiplying the conver variable). Now an output variable is created as the summation of the curve variables just mentioned. We now use the plot command to plot all three curves on the same graph as shown above.
No comments:
Post a Comment