matlab revision sheet final 15-16 - version 4

30
Revision Sheet For MATLAB The following sheet contain some problem with a suction sample please try to do your bets to gain the maximum benefits. The sheet contain theoretical part, command line part ,m-file and function file part, as well as Simulink part VIP HINTS *Please in all of the following parts try to show how to run each m-file program , function file or command lines and show the results as possible as you can * When using plot command please assign the different labels on the x-y axis and put a suitable title for each figure a) During debugging process of MATLAB programs, there are many types of errors may appear. Explain them briefly? *Syntax Errors: the violation of the rule for the specified language, the program will not be compiled. This usually caused by missing left or right parentheses, misspelled commands, or other types. Solution :check the listed line of code for the syntax error and correct it then test the program again. * Logical error-wrong answer: it is the most difficult to locate, this error is usually caused by a misplaced parentheses (or lack of parentheses especially in the denominator of a fraction), reserved or incorrect +/- signs, or the wrong variables used in an equation. Solution: Break down large equations into smaller, less complicated steps, and display the results of the intermediate steps (remove the semi-colons ; ). Remember the key board interrupt will allow you to pause a program within a loop and display intermediate values. * logical error-program terminates early: sometimes it is called a Run time error since all syntax are good but if you put a mathematical violation. this 1

Upload: anonymous-zwlycna5

Post on 26-Jan-2016

14 views

Category:

Documents


2 download

DESCRIPTION

Matlab Revision Sheet Final 15-16 - Version 4

TRANSCRIPT

Page 1: Matlab Revision Sheet Final 15-16 - Version 4

Revision Sheet For MATLAB

The following sheet contain some problem with a suction sample please try to do your bets to gain the maximum benefits. The sheet contain theoretical part, command line part ,m-file and function file part, as well as Simulink partVIP HINTS *Please in all of the following parts try to show how to run each m-file program , function file or command lines and show the results as possible as you can* When using plot command please assign the different labels on the x-y axis and put a suitable title for each figurea) During debugging process of MATLAB programs, there are many types of errors may appear. Explain them briefly?*Syntax Errors: the violation of the rule for the specified language, the program will not be compiled. This usually caused by missing left or right parentheses, misspelled commands, or other types. Solution :check the listed line of code for the syntax error and correct it then test the program again. * Logical error-wrong answer: it is the most difficult to locate, this error is usually caused by a misplaced parentheses (or lack of parentheses especially in the denominator of a fraction), reserved or incorrect +/- signs, or the wrong variables used in an equation. Solution: Break down large equations into smaller, less complicated steps, and display the results of the intermediate steps (remove the semi-colons ; ). Remember the key board interrupt will allow you to pause a program within a loop and display intermediate values.* logical error-program terminates early: sometimes it is called a Run time error since all syntax are good but if you put a mathematical violation. this error is usually caused by an index that exceeds matrix dimensions, a variables that doesn't exist (or has been misspelled), or and indexed variables should not be indexed (or visa-versa)Solution: list the size of the variables using the "whos" MATLAB command .look for the missing variables or incorrect dimensions (especially for the transposed vectors/matrices). If the error occurs in a loop, examine the loop index to see what was the last value of the index.*GHOST characters: This is a character that is not displayed on the screen or when printed, but it is recognized when compiled. If you are sure that a line of code is correct, but the MATLAB won't compile it or run it, it is possible that there is a "GHOST" character in the line. Since you can't edit this character, the solution is to delete the entire line of code and retype the line from the keyboard. While "ghost" characters should not appear in a file, it has been my experience that they do show up every once in a while. If you really think that a line of code is correct, it just might be correct

1

Page 2: Matlab Revision Sheet Final 15-16 - Version 4

b) With the aid of block diagram representing the general form of Simulink model define what is meant by MATLAB SIMULINK?, and WHAT is simulink good for?

C) State some of the basic features of the MATLAB software package?ANS: *MATLAB is a numeric computation software for engineering and scientific calculations. The name MATLAB stands for MATRIX LABORATORY.*MATLAB is primarily a tool for matrix computations. *MATLAB is a high-level language whose basic data type is a matrix that does not require dimensioning. *There is no compilation and linking as is done in high-level languages, such as C or FORTRAN. *Computer solutions in MATLAB seem to be much quicker than those of a high-level language such as C or FORTRAN. *All computations are performed in complex-valued double precision arithmetic to guarantee high accuracy. MATLAB has a rich set of plotting capabilities. *The graphics are integrated in MATLAB. *Since MATLAB is also a programming environment, a user can extend the functional capabilities of MATLAB by writing new modules.*MATLAB has a large collection of toolboxes in a variety of domains. Some examples of MATLAB toolboxes are control system, signal processing, neural network, image processing, and system identification. The toolboxes consist of functions that can be used to perform computations in a specific domain.*Moreover the MATLAB contain a SIMULINK. It is a software package for modeling, simulating, and analyzing dynamic systems. It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two. Systems can also be multirate, i.e., have different parts that are sampled or updated at different rates

PART_I- basic operation using command

A=[ i 4 22 e−3 1007 9 7− j3 8 42

]B=A2

1. Represent A, B using MatlabA = [ j , 4, 2 ; 2, exp (-3), 100 ; 7, 9, 7-j; 3, 8, 42]B = A . ^ 2 % element – by – element square as A is not a square matrix

2- Write MATLAB expression using command lines to achieve the following:a) Select just the second row of B

B (2, :)

2

Page 3: Matlab Revision Sheet Final 15-16 - Version 4

b) Evaluate the sum of the second row of BSum (B (2,:)

c) Multiply the second column of B and first column of A

B (:, 2) *. A (: ,1) (element – by – element multiplication) Or B ( : , 2) * A (:, 1) ' (Vector multiplication so one of the 2 vectors must be transposed)

d) Evaluate the maximum value in the vector resulting from element by element multiplication of second column of B with first column of A

max (B ( : , 2) * A (:, 1) )

e) Evaluate the sum of the first row of A divided element by element by the first three elements of the three elements of the third column of B

Sum (A (1, :) . / B (: , [1: 3] ) ' ) % dividing a row element – by – element by a column so we must transpose one of them

f) Convert matrix A into matrix of dimension (6X2).

Reshape ( A , 6, 2)

g) find the transpose of B

B 'h) calculate A-1 .B

inv (A) * B

i) multiply first element at the third row of A by the third element at the first column of B

A (3,1) * B (3, 1) % scalar multiplication, so no need to put the . operator

2-Using MATLABE function file line to evaluate the complex number Z in both polar and rectangular form given asZ=(1-i).e3π sin-1(0.5).(3+4j)-1.e-j30 .5450

Solution:

Z1 = (1 – i) * exp (3*pi)Z2 = asin (0.5) * 1 / (3 + 4* j) % asin is the representation of sin -1 in MatlabZ3 = exp ( - j * 30) * 5 exp (j * 45 * pi / 180) % theta rad = theta degree * pi /180Z = Z1 * Z2 * Z3

3

Page 4: Matlab Revision Sheet Final 15-16 - Version 4

II-Polynomials operations and symbolic

Solution:Note: Symbolic Math will not come in the exam, so question 10 is not required

4- [ q, r ] = deconv ( [ 14, -6, 3, 4 ] , [ 5, 7, -4] ) % where q is the quotient (القسمة ) r is the remainder ,(خارج القسمة (باقى

5 – y = 0.5 + j * 6 + 3.5 * exp (j * 0.6) + ( (3 + j *6) * exp ( j * 0.3 * pi) )

6 – r = roots ( [ 1, 3, 4, 2, 6] )

To plot f (x) there are 2 methods: the first is repsresnting f (x) as a symbolic function (which will not come in the exam) and the second is representing f (x) as a polynomial

Assume x is in the range from -2 <= x <=2 with a step = 0.5

So the solution as a script file will be:1- p= [1, 3, 4, 2, 6] 2- x = -2 : 0.5 : 23- y = polyval (p, x)4- plot (x, y)

the required 7, 8 will be solved as no. 4 but with changing the coefficients

9 – result = conv ([ 14, -6, 3, 4 ] , [ 5, 7, -4 ] ) % conv is the polynomial convolution function which multiplies 2 polynomials together------------------------------------------------------------------------------------------Part_ 2 application of Function and M. files in MATH.

4

Page 5: Matlab Revision Sheet Final 15-16 - Version 4

Pleas in all of the following parts try to show how to run each m-file program , function file or command lines and show the results as possible as you can1-Write a general matlab script m-file to plot the two functions in the same figure with different line style assign the different lables on the x-y axis and put a suitable tiltle for each figure

Solution:

1- x1 = 0 : 0.5 : 52- x2 = -6: 0.5 : 63- f = exp (-1.2 *x ) * sin (10*x + 5)4- y = abs (x . ^ 3 – 100)5- plot (x1,f)6- xlabel ('x1')7- ylabel ('f (x) ')8- title (' exponential_sinusoidal function ')9- legend (' f (x) ')10-hold on11-plot (x2,y)12-xlabel ('x2')13-ylabel ('y ')14-title (' absolute cubic function ')15-legend (' y ')

2- Write a script file to plot the polynomial

Over the range -6 <= x < 6with spacing of 0.01

Solution:1- x = -6 : 0.01: 62- p = [2 , 2, -100, -2, -7, 90 ] % polynomial of degree 5 has 6

coefficients3- y = polyval (p , x)4- plot (x, y)

3-Write a functional file to evaluate n factorial (i.e. n!) where n ! = n (n-1) (n-2)(n-3)….(2 )(1)

Solution:

function fact = factorial (n)n = input (' enter a number ')fact = 1for i = 1 : n

5

Page 6: Matlab Revision Sheet Final 15-16 - Version 4

fact = fact * iend % end of the for loopfact % the function returns the value of factend % end of the function file

4- Write a MATLAB function to add all the odds numbers from 0 to n (at each run nis changed) Add all the terms in the series

Print out the sum of 10 terms

Solution:

1- function [ sum ] = series (n)2- n = input ('Enter the number of terms of the series')3- sum = 04- for i = 1 : n5- sum = sum + 1 / ( (2 * i ) + 1 ) % the general term = 1 / (2i + 1)6- end % end of the for loop7- sum % return the value of sum8- end % end of the function file

To run this general function File press f5 (or from the Debug Menu select Run)When the Command Windows appears, this message will be displayed>> Enter the number of terms of the series>> n = 10The output will be: 1 + 1/3 + 1/5 + 1/7 + 1/9 + 1/11 + 1/13 + 1/15 + 1/17 + 1/19 = 0.05595 ( not required)

5-Given a set of integers ranged from 0 to N, Write a MATLAB function to assign the even and odd numbers in each case find the sum of each part

6- Write a MATLAB function to add all the numbers according to the following series1+2+4+6+8+…….

Solution:

1- function [ sum ] = series (n)2- n = input ('Enter the number of terms of the series')3- sum = 14- for i = 2 : n5- sum = sum + ( i - 1 ) * 26- end % end of the for loop

6

Page 7: Matlab Revision Sheet Final 15-16 - Version 4

7- sum % return the value of sum8- end % end of the function file

7- Write a MATLAB function to add all the numbers according to the following series

Z¿∑x=0

n

x2

Solution:

1- function [ sum ] = series (n)2- n = input ('Enter the number of terms of the series')3- sum = 04- for i = 0 : n5- sum = sum + ( i ) ^ 26- end % end of the for loop7- sum % return the value of sum8- end % end of the function file

8- Determine the number of consecutive integer numbers which when added together will give a value ≤ "max_value". Run such program for max_value= 210.

Example 3.3, page 34 (Lecture Book) (using while loop and if statement)

9- Write MATLAB script file to show and generate the following series ( numbers from 0 to n ) 1 ,2 , 4 , 9, 16 ,25 ,36, ……

Solution:1- n = input ('Enter the number of terms of the series')2- A (1) = 13- A (2) = 24- for i = 3: n5- A (i) = ( i – 1) ^ 26- end % end of the for loop7- disp (A) % display the vector A

10- Write a MATLAB script file to show and generate the following series (numbers from 0 to n). The recursion relation is assumed according to the followingAi = Ai-1 + Ai-2

7

Page 8: Matlab Revision Sheet Final 15-16 - Version 4

i.e the new term starting from the third term is sum of the two previous terms as follows1 ,1 ,2 ,3 ,5 ,8,13,21,34 ……

Solution:1- n = input ('Enter the number of terms of the Fibonacci series')2- A (1) = 13- A (2) = 14- for i = 3: n5- A (i) = A (i-1) + A (i-2)6- end % end of the for loop7- disp (A) % display the vector A

Part_ 3 application of Function and M. files in electronics.

11- For in the op. Amp shown, in figure (a ) Derive the expression for the transfer function. Then write general matlab script file to find the frequency response for such amplifier , Explain how to run such file assuming the following values (b) If C = 1 nF and R1 = 2K, plot the magnitude response for the different values of R2 as follows equal to(i) 100 K, (ii) 300K, and (iii) 500K.

8

Page 9: Matlab Revision Sheet Final 15-16 - Version 4

Sample of MATLAB Script r try to play it as general file

% Frequency response of lowpass circuit

C=input(‘plz enter the value of c = 1e-9; r1 = 2e3;r2 = [100e3, 300e3, 500e3];n1 = -1/(c*r1); d1 = 1/(c*r2(1));num1 = [n1]; den1 = [1 d1];w = logspace (-2,6);h1 = freqs (num1,den1,w);f = w / (2*pi);

12- For the non-inverting type O.A shown in Figure below (a) Derive the transfer function. (b) Use MATLAB general m-file to find the poles and zeros and Plot the magnitude and phase response,. Explain how to run such file assuming the following values: C1 = 0.1uF, C2 = 1000 0.1uF, R1 = 10K, and R2 = 10 .

9

Page 10: Matlab Revision Sheet Final 15-16 - Version 4

10

Page 11: Matlab Revision Sheet Final 15-16 - Version 4

13- In the above Figure 11.15, of finite gain O.A write a matlab script m-file to drive the above expression then assume R1 = 500 Ω, and R2 = 50 KΩ Plot the closed-loop gain as the open-loop gain increases from 102 to 108 .

14- The following example illustrates the effect of a finite CMRR on the closedloop gain of a non-inverting For the amplifier shown in Figure 11.22, if R2 = 50Kand R1 = 1K, plotthe closed-loop gain versus CMRR for the following values of the latter:104 , 105 , 106 , 107 , 108 and 109 .amplifier.

% Non-inverting amplifier with finite CMRRr2 = 50e3; r1 = 1.0e3; rr = r2/r1;cmrr = logspace(4,9,6); gain = (1+rr)*(1+1./cmrr);semilogx(cmrr,gain,'wo')xlabel('Common-mode Rejection Ratio')ylabel('Closed Loop Gain')title('Gain versus CMRR')axis([1.0e3,1.0e10,50.998, 51.008])

15-For the genral RC circuit Figure 5.2, write MATLAB function file to study the case of charging and discharging the capacitor if the input voltage is a rectangular pulse with an amplitude of 5V and a width of 0.5s. If C = 10 uF,

11

Page 12: Matlab Revision Sheet Final 15-16 - Version 4

plot the output voltage, vo( t), for resistance R equal to (a) 1 Kohm and (b) 10 KΩ. The plots should start from zero seconds and end at 1.5 seconds.

For the series RLC circuit the transfer function (T.F) is given as:

Write a general MATLAB program to obtain the magnitude and phase response, as well as calculate the poles,zeros, and gain of this T.F. Run such program for the given values: If L = 5 H, C = 1.12 uF, and R = 10000 ohm, plot the frequency response.16) After performing the DC_ analysis of a certain electrical circuit using NODAL VOLTAGE technique, the following equations are concluded:5 V1 -3 V2 -8 V3 =100.4 V1 -0.7 V2 -1.5 V3 =015 V1 -25 V2 -14 V3 =2Where all the above coefficients are representing [Y] matrix. Write a MATLAB script file to solve such problem guided with the equation in matrix form: [V] =[Y]-1 [I]17) Write a MATLAB function file to calculate equivalent resistance for group of series and parallel connected resistance. Display suitable messages in each case. Then show different steps to run this function for the values R=10,20 and 30 Ω.

12

Page 13: Matlab Revision Sheet Final 15-16 - Version 4

function [ rs rp ] = rsp( r )%UNTITLED2 Summary of this function goes here% Detailed explanation goes herers=sum(r); % statement for the equivalent series resistanceg=1./r;% statement for the conductancegs=sum(g);% statement for the equivalent series conductancerp=1/gs;% statement for the equivalent parallel resistanceend

Another Solution (using for loop)function [ rs, rp ] = rsp ( r )r=input('Enter n resistances')rs = 0;rp = 0;for i = 1 to length (r)rs = rs + r(i); rp = rp + 1 / r(i);end % end of the for looprs1/rpend % end of the function file

to run such function usingcommand windows as follows

a) The voltage V, across a resistance is given as (Ohm’s law) V=RI, where R is the resistance, and I is the current. The power dissipated in resistor R is given by the expression P=RI2 . Write a general MATLAB script file to calculate the voltage and power across resistance R. Then show how to run the program to test the result if R=10 and the current I is ranged from 0 to 10 A with increments of 2A.

% general program for power calculation diary ex1_1.datclear all close all

13

Page 14: Matlab Revision Sheet Final 15-16 - Version 4

seta=input('enter the phase shift between current and voltage seta=')setar=seta*pi/180;%pf=cos(setar);% power factory=input('index y=1 given I,V- y=2 given R,V y=3 given R,I y=') pf=cos(setar);% power factorif y==1 I=input(' enter the value of current I=') ; V=input(' enter the value of current V=') ; P=I.*V.*pf % general form of powerelseif y==2 R=input(' enter the value of resistance R=') ; V=input(' enter the value of voltage V=') ; P=V.^2./R.*pf % general form of powerelse R=input(' enter the value of resistance R=') ;I=input(' enter the value of current I=') ;P=I.^2.*R.*pf % general form of powerend

14

Page 15: Matlab Revision Sheet Final 15-16 - Version 4

HINT for SIMULINK: GENERALLY: Open the MATLAB SIMULINK tool box using the start menu of the MATLAB or using the command window >> Simulink. Or using the toolbox icon . then from the Simulink toolbox apply the following sequence to create a new model fileFile-Newmodelcreate new modelApply the rule of drag and drop from the different library to get the different SOURCE- library" and different "SINK- library" to create the model for the different problem. By double click for the different box we can establish the different parameters. And then click on the play toolbox to run the model we designedFrom source library drag and drop the "ramp" function boxFrom the sink library drag and drop the "scope" function boxFrom the continuous library drag and drop "transfer fcn" boxAnd so on foe all the other library according to the given problem (hint try to use the search command box to search about the unknown boxes) and FINALLY DRAW THE MODEL ACCORDING TO THE GIVEN PROBLEMa) Construct simulation diagram satisfying the equationx(t)= 10sin(100t+20cos(100t)+30tb) Explain how to use SIMULINK tool box to model the equation that convert Celsius temperature to Fahrenheit as: Tf= 9/5 Tc+32 Obtain a display of Fahrenheit-Celsius temperature graph over range of 0 to 1000C

Solution:

General Simulink Model:

Applying this model on the given problem:

1- Open the Simulink from Matlab Command Window >> simulink

2- Once the Simulink is opened, the Simulink Library Browser (the place of the system components and blocks) appears

15

Source (input waveforms or imported from an external file )

System (interconnected links

between different blocks like integrator,

derivative, Multiplexer, transfer

function, etc…)

Sink (output either on scope

or exported to an external file)

Page 16: Matlab Revision Sheet Final 15-16 - Version 4

3- From the Simulink Library Browser menu open the file menu then new then model4- In the model window design the model of the given problem using the drag – and – drop concept (drag the blocks from the Simulink library browser and then drop them with the suitable connections in the model)

To model the equation that converts Celsius temperature to Fahrenheit

TF = 9/5(TC) + 32

First, consider the blocks needed to build the model:

A Ramp block to input the temperature signal, from the Sources library

A Constant block to define a constant of 32, also from the Sources library

A Gain block to multiply the input signal by 9/5, from the Math Operations library

A Sum block to add the two quantities, also from the Math Operations library

A Scope block to display the output, from the Sinks library

Next, gather the blocks into your model window.

Assign parameter values to the Gain and Constant blocks by opening (double-clicking) each block and entering the appropriate value. Then, click the OK button to apply the value and close the dialog box.

Now, connect the blocks.

The Ramp block inputs Celsius temperature. Open that block and change the Initial output parameter to 0. The Gain block multiplies that temperature by the constant 9/5. The Sum block adds the value 32 to the result and outputs the Fahrenheit temperature.

Open the Scope block to view the output. Now, choose Run from the Simulation menu to run the simulation. The simulation runs for 10 seconds.

16

Page 17: Matlab Revision Sheet Final 15-16 - Version 4

Part one Mathematical Manipulation

A=[3−i 4 22 4 1007 9 73 8 42

]B=A2

17

Page 18: Matlab Revision Sheet Final 15-16 - Version 4

1-Write MATLAB expression to do the following a) Select just the second row of Bb) Evaluate the sum of the second row of Bc) Multiply the second column of B and first column of Ad) Evaluate the maximum value in the vector resulting from element by

element multiplication of second column of B with first column of Ae) Evaluate the sum of the first row of A divided element by element by

the three elements of the three elements of the third column of Bf) Convert matrix A into matrix of dimension (6X2).

2-Using MATLABE to evaluate the complex number

z=(3+ j 4 )(6+ j6 )

(2+ j1) j 2+7+ j 10

3-

A=[11 4 3012 2 π 1017 9 5 π3 π 42

]B=eA

Show how to represent A, B in Matlab

A = [11 , 4, 30; 12, 2*pi, 10; 17, 9, 5*pi; 3, pi, 42]B= exp (A) Write MATLAB expression to do the following

a) Select just the third row of BB (3, :)

b) Evaluate the sum of the first row of Bsum (B (1, :) )

c) Multiply the second column of A and first column of BA (: , 2) . * B (:, 1) (element – by – element multiplication so we need to use .*)Or: A (: , 2) * B (: , 1) ' (normal matrix multiplication so we need to transpose one of the 2 matrices)

d) Evaluate the maximum value in the vector resulting from element by element multiplication of second column of B with first column of A

max ( (B (: , 2) . * A (: , 1) )

e) Evaluate the sum of the first row of A Multiplied element by element by the three elements of the three elements of the third column of B

sum ( A (1, :) . * B (: , [1:3] ) ' ) ( element – by –element multiplication of rows and columns so we need to transpose one of them )

Polynomials

18

Page 19: Matlab Revision Sheet Final 15-16 - Version 4

4 -Using MATLAB to find the quotient and reminder of

14 x3−6 x2+3 x+45 x2+7 x−4

P = [14, -6, 3, 4] (polynomial of degree 3 having 4 coefficients)Q = [5, 7, -4] (polynomial of degree 2 having 3 coefficients)

[a, b] = deconv (P, Q) (where a will be the quotient (coefficients القسمة خارجشكل while b will be the remainder (coefficients ( على شكل على القسمة باقى

)

5- Using MATLABE to simplify the expressiony=0. 5+ j6+3. 5e j 0.6+(3+ j6 )e j 0. 3 π

6-Using MATLABE to find the roots of f ( x )=x4+3 x3+4 x2+2 x+6 using two methods plot f ( x )

7-Using MATLAB to find the quotient and reminder of

10 x3−9x2−6 x+125 x3−4 x2−12 x+8

8- Using MATLAB to find the quotient and reminder of

8 x3−9 x2−710 x3+5 x2−3 x−7

9- Using MATLAB to find the multiplication of the following functionsf 1 ( x )=14 x3−6 x2+3 x+4 , f 2( x )=5 x2+7 x−4

f1 = [14, -6, 3, 4]f2 = [5, 7, -4]

F = conv (f1, f2)

Part 2 Function and M. files1-Write a script file to plot the two functions in the same figure with different line style

f ( x )=e−1. 2 x sin (10 x+5 ) for 0≤x≤5and function y=|x3−100|for −6≤x≤6

2-Write a functional file to evaluate n factorial (i.e. n!) where n ! = n (n-1) (n-2) (n-3)….(2 )(1)

Using the function to compute x= 7 !

3 ! 4 !

3- Write a MATLAB function to add all the odds numbers from 0 to n (at each run n is changed)Add all the terms in the series

1+ 13+ 1

5+1

7+. .. . .. .. . .+ 1

2 n+1 where n=0,1,2. .. . .

Print out the sum of 10 terms

19

Page 20: Matlab Revision Sheet Final 15-16 - Version 4

4- Write a for loop that is equivalent to the command sum(A) where

A=[ 3 24 52 20 131 9 11

24 8 12]

5- Write a for loop that is equivalent to the command max(A) where

A=[ 3 24 52 20 131 9 11

24 8 12]

6- Write a for loop that is equivalent to the command min(A) where

A=[ 3 24 52 20 131 9 11

24 8 12]

7- The voltage across discharging capacitors is

v ( t )=10(1−e−0 . 2t )generate a table

of voltage v(t), versus time t, for t=0 to 50 seconds with increment of 5 second find the number of points of vector t8- Write a MATLAB function to add all the evens numbers from 0 to n (at each run n is changed)9- Write a script file to plot the polynomial 2 x5+2 x4−100 x3−2 x2−7 x+90

Over the range −6≤x≤6 with spacing of 0.01

Final Exam Notes:

- Most of the questions come in the form of "write a general M – File (without values) then show how to run this file for the give values "

- Symbolic Math will not come in the exam (ملغى)

- Simulink will come as the problem we have solved in the last section (similar to the last question in the last year final exam that I have given to you and uploaded on the group)

- Any programming problem taken in C++ can come in the Matlab exam (like factorial, power, maximum element of the array using for loop without using the max built-in function etc…)

- According to Doctor Fouda, the supplementary problems in this sheet are only for understanding buit will not come in the exam (so, I removed them from the sheet )

20

Page 21: Matlab Revision Sheet Final 15-16 - Version 4

- All the examples in the Lecture Book that Doctor Fouda has explained are important, and the Doctor takes these examples into consideration in the final exam. In the next update of these notes INSHALLAH, I will try to inform you of the most important problems

- Your Mid - Term Exam of 2015 is very important. I gave you the model answer of Dr. Fouda which is also uploaded on the group.

Important Problems and Notes in Lecture Book:

Chapter "1": Matlab Basics and Foundations:

Page "1": 1- Introduction: Definition and Applications of Matlab

Pages "11", "12" : Examples 1.1, 1.2

Pages "15", 16: Ex 1.1, 1.4 (very important), 1.7 (very important)

Chapter "2": Plotting Commands:

Page "22", Ex. 2.1

Page "25", Ex. 2.3 (polar plot, very important)

Page "27", Examples 2.3, 2.4, 2.7, 2.8

Chapter "3": Control Statements (Programming using Matlab:

Page "28": ex. P2.m, page "29": ex. P3.m (Mid – Term)

Page "33": ex. 3.2 (A/D Converter, very important)

Page "34", ex. 3.3

Page "39", ex. 3

21

Page 22: Matlab Revision Sheet Final 15-16 - Version 4

Page "40", ex. 1.4 (Quadratic Equation)

Chapter "4": DC Analsyis

Chapter "5": AC Analysis, Frequency Response , Semiconductors and Op – Amps

Notes:

1- In this chapter we need the function "logspace" which takes the following form:

logspace (power of start frequency, power of end frequency, number of frequencies)

Example: if doping concentration is from 10 14 to 10 19 cm -3

Then N d (doping concentration) = logspace (14, 19) (if the number of frequencies was not given, the logspace takes 2 parameters only)

2- Also we need the freqs function which calculates and represents the transfer function H (s) in the form of:

H = freqs (num, den, w)

Where num is the numerator of the polynomial H (s)

, den is the denominator of the polynomial H (s)

, w is the omega (w = 2 * pi * f, so f = w / (2 * pi)

- So firstly we must represent h (s) as 2 polynomials one for the numerator (

each polynomial is in the ,(المقام) and the other for the denominator , (البسطform of (n+1) coefficients

- Then represent w (omega) in the form of logspace function (as explained

previously)- Finally calculate h (s) using the freqs function

Important Examples in Chapter "5":

AC analysis : Example "5.1": page 70, Ex. 5.2: pages 71, 72 (Very important)

Frequency Response: Example 6.7: pages "74", "75" (Very Important)

Chapter "6": Introduction to Simulink:

22