{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 2: The circuit elements" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1_a: Determine_the_current_flow_and_voltage_drop_across_the_resistor.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "V = 1; // voltage supply \n", "R = 10; // resistance in ohms \n", "I = V/R //current flowing through R\n", "disp('a)')\n", "disp(V,'voltage across the resistor (in volts)=')\n", "disp(I,'current flowing through the resistor (in amps) =')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1_b: Determine_the_current_flow_and_voltage_drop_across_each_resistor.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "V = 1; // voltage supply \n", "R1 = 10; // first resistance in ohms \n", "R2 = 5; //resistance of the second resistor \n", "Vr1 = V * (R1/(R1 + R2)); //voltage across R1\n", "Vr2 = V - Vr1; //voltage across R2\n", "Ir = Vr1/R1; //current flowing through R\n", "\n", "disp(Vr1,'voltage across the first resistor (in volts)=')\n", "disp(Vr2,'voltage across the second resistor (in volts)=')\n", "disp(Ir,'current flowing through the resistor (in amps) =')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1_c: Repeat_parts_A_and_B_with_the_voltage_source_replaced_by_a_current_source_of_1A.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//c - a\n", "R1 = 10; // first resistance in ohms\n", "I = 1; // current source \n", "V = I*R1; // voltage across R\n", "disp('c - a)')\n", "disp(V,'voltage across the resistor (in volts)=')\n", "disp(I,'current flowing through the resistor (in amps) =')\n", "\n", "//c - b\n", "Vr1 = I*R1; // voltage across R1\n", "Vr2 = I*R2; //voltage across R2\n", "disp('c - b)')\n", "disp(Vr,'voltage across the resistor (in volts)=')\n", "disp(I,'current flowing through the resistor (in amps) =')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.2: EX2_2.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "R = 100; // resistance in ohms\n", "I = 0.3; // current in amps \n", "P = I^2 * R; // power \n", "//power specification of the resistors available in the stock \n", "Pa = 5;\n", "Pb = 7.5;\n", "Pc = 10;\n", "\n", "if Pa > P then\n", " disp('we should select resistor a')\n", "end\n", "if Pb > P then\n", " disp('we should select resistor b')\n", "end\n", "if Pc > P then\n", " disp('we should select resistor c')\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3: EX2_3.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "L = 1; //length of the copper wire in meters\n", "A = 1 * 10^-4; // cross sectional area of the wire in meter square \n", "rho = 1.724 * 10^-8; // resistivity of copper in ohm meter\n", "R = rho*L / A; // resistance of the wire in ohm \n", "\n", "disp(R, 'resistance of the wire (in ohms)=') " ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.4: EX2_4.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//1 inches = 0.0254meters\n", "//1 foot = 0.3048 meters\n", "d = 0.1*0.0254; // diameter of the wire in meters\n", "L = 10*0.3048; //length of the wire in meters \n", "rho = 1.724*10^-8; // resistivity of the wire in ohm-meter\n", "A = %pi*(d/2)^2; // cross sectional area of the wire \n", "R = rho*L/A; //resistance of the wire in ohm \n", "disp(R,'resistance of the wire (in ohm)=')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.5: EX2_5.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "L = 0.1; // inductance of the coil in henry \n", "t1 = [0:0.001:0.1];\n", "t2 = [0.101:0.001:0.3];\n", "t3 = [0.301:0.001:0.6];\n", "t4 = [0.601:0.001:0.7];\n", "t5 = [0.701:0.001:0.9]\n", "//current variation as a function of time \n", "i1 = 100*t1;\n", "i2 = (-50*t2) + 15;\n", "i3 = -100*sin(%pi*(t3-0.3)/0.3);\n", "i4 = (100*t4) - 60;\n", "i5 = (-50*t5) + 45;\n", "\n", "t = [t1,t2,t3,t4,t5];\n", "i = [i1,i2,i3,i4,i5];\n", "plot(t, i)\n", "\n", "dt = 0.001;\n", "di = diff(i);\n", "V = L*di/dt; //voltage drop appearing across the inductor terminals\n", "Tv = [0:0.001:0.899];\n", "plot(Tv, V, 'green')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.6: Find_the_time_variation_of_the_capacitor_voltage.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "C = 0.01; // capacitance of the capacitor in Farads\n", "t1 = [0:0.001:0.1];\n", "t2 = [0.101:0.001:0.3];\n", "t3 = [0.301:0.001:0.6];\n", "t4 = [0.601:0.001:0.7];\n", "t5 = [0.701:0.001:0.9]\n", "//current variation as a function of time \n", "i1 = 100*t1;\n", "i2 = (-50*t2) + 15;\n", "i3 = -100*sin(%pi*(t3-0.3)/0.3);\n", "i4 = (100*t4) - 60;\n", "i5 = (-50*t5) + 45;\n", "\n", "t = [t1,t2,t3,t4,t5];\n", "i = [i1,i2,i3,i4,i5];\n", "plot(t, i)\n", "\n", "// voltage across the capacitor as a function of time \n", "V1 = (1/C)*integrate('100*t','t',0,t1);\n", "V2 = (1/C)*integrate('(-50*t)+15','t',0.101,t2);\n", "V3 = (1/C)*integrate('-100*sin(%pi*(t-0.3)/0.3)','t',0.301,t3);\n", "V4 = (1/C)*integrate('(100*t) - 60','t',0.601,t4);\n", "V5 = (1/C)*integrate('(-50*t) + 45','t',0.701,t5);\n", "V = [V1, V2, V3, V4, V5];\n", "\n", "plot(t, V, 'green')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.7: EX2_7.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//a\n", "Ri = 1; \n", "Rf = 39;\n", "A = 10^5; //open loop gain of the op-amp\n", "G = A/(1 + (A*Ri/(Ri+Rf))); //actual voltage gain of the circuit \n", "disp('a')\n", "disp(G,'actual voltage of the circuit =')\n", "\n", "//b\n", "G1 = 1 + (Rf/Ri); // voltage gain of the circuit with infinite open loop gain\n", "disp('b')\n", "disp(G1,'for ideal case the voltage gain =')\n", "\n", "//c\n", "er = ((G1 - G)/G)*100; //percent error \n", "disp('c')\n", "disp(er,'percent error of the ideal value compared to the actual value=')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.8: Design_a_non_inverting_opamp_circuit_of_voltage_gain_4.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "G = 4; // voltage gain of the circuit \n", "r = G -1; // ratio of the resistances in the non-inverting op-amp circuit\n", "disp(r,'Rf/Ri =')\n", "//Result:\n", "//A suitable choice for R1 is 10K, Hence Rf = 30K" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.9: Find_the_input_resistance_of_an_inverting_opamp_circuit_with_voltage_gain_of_4.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "G = 4;\n", "r = G; // ratio of the resistances in the inverting op-amp circuit\n", "disp(r,'Rf/Ri')\n", "//Result;\n", "//A suitable choice for Rf=30K and R1=7.5K\n", "//therefore input resistance R1 = 7.5K" ] } ], "metadata": { "kernelspec": { "display_name": "Scilab", "language": "scilab", "name": "scilab" }, "language_info": { "file_extension": ".sce", "help_links": [ { "text": "MetaKernel Magics", "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" } ], "mimetype": "text/x-octave", "name": "scilab", "version": "0.7.1" } }, "nbformat": 4, "nbformat_minor": 0 }