Course Update

## EEE 306 Lab 8 : Introduction to Matlab

This Lab is about an introduction to matlab.

The objective of this lab is to learn about

• Basic mathematical and logical operator in matlab
• Working with Matrix and vector
• Use of conditional ‘if’
• Use of for and while loop

Practice script

``` %Basic matrix operation
a=[1 2 3;4 5 6;7 8 9]
b=[3 2 1;6 5 4;9 8 7]
c=a+b
d=a*b
n=5
e=a+n*c

%Use of if, while and for
%while 1 %Try not to use while 1 in matlab. It is not a good idea.
total=0
for i=0:1:5
mark= input('What is the mark ')

if mark >=90
point=5;
elseif mark>=80
point=4;
elseif mark>=70
point=3;
elseif mark>=60
point=2;
elseif mark>=50
point=1;
else
point=0;
end % end of if
total=total+point;
end %end of for loop

total=total/6

%end % end for while loop```

MATLAB intro

## EEE 306 Lab 7 : Open methods for finding roots

Write a program to use fixed point iteration to solve the equation f(x)=e^(-x) – x where inputs will be the initial guess, maximum number of iterations and maximum error (es). If the approximation error (ea) is less than es your program should stop continuing any iterations.

Write a program to use Newton Raphson Method to solve the equation f(x)=e^(-x) – x where inputs will be the initial guess, maximum number of iterations and maximum error (es). If the approximation error (ea) is less than es your program should stop continuing any iterations.

Write a program to use  Secant Method to solve the equation f(x)=e^(-x) – x where inputs will be the initial guess, maximum number of iterations and maximum error (es). If the approximation error (ea) is less than es your program should stop continuing any iterations.

## CSE 505 Term Test 2

Date: Tuesday, 25th September 2017

Syllabus: Lecture 4,5,6,7

Question: [Still to come]

Marks: [Still to come]

## CSE 305 Term Test 2

Date: Tuesday, 23rd September 2017

Syllabus: Lecture 4,5,6

Question: [Still to come]

Marks: [Still to come]

## CSE 505 Lab 7

Practise #1 (Section 6.5)
Write a code to take a string input and print the first and last capital letters in the string in alphabatical order

```//code
TITLE First and last capitals
.MODEL SMALL ; DIRECTIVE
.STACK 100H
.DATA ;
CR EQU 0DH ;
LF EQU 0AH ;
;A DW 2 ; DATA SEGMENT
;B DW 5 ;
;SUM DW ? ;
msg db 'Type a line of text',cr,lf,'\$'
msg_nocap db cr,lf,'There is no capital\$'
cap_msg db cr,lf, 'First Capital = '
first db ']'
db ' Last Capital = '
last db '@\$'

.CODE ;
MAIN PROC ;MAIN PROCEDURE ; CODE SEGMENT
MOV AX,@DATA ;
MOV DS, AX ;

mov ah, 9
lea dx, msg
int 21h

MOV AH, 1
INT 21h
while:
cmp al, cr
je end_while

;STaring of if statement
;if
cmp al,'A'
jnge end_if
cmp al, 'Z'
jnle end_if
;then
cmp al, first
jnl check_last
mov first, al

check_last:
cmp al, last
jng end_if
mov last,al

end_if:

int 21h
jmp while
end_while:

mov ah, 9

cmp first,']'
jne cap

lea dx, msg_nocap
jmp display

cap:
lea dx, cap_msg

display:

int 21h

;Exit code
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN```

Problem #1
Write a code to take a string input and print the first and last capital letters in the string as appeared in the string

Example
input:
Hello this is a test A
output:
First capital = H Last capital = A

Problem #2

Dispay the extended ascii characters from 80h to FFh with only 10 ascii characters per line with a space between each characters.

Marut chapter 6 practice problem 9,10,11

Submit Assignment 4[Lab 6 and 7] through this link

## EEE 306 Lab 6 : Bracketing methods for finding roots

Write a program to find root of an equation in the form ax^2+bx+c, where a,b,c, will be taken as input. You have to take input the number of iteration and the termination criterion.

Use bisection method to find the root where the upper limit and lower limit will be taken as input.

Write a program to find root of an equation in the form ax^2+bx+c, where a,b,c, will be taken as input. You have to take input the number of iteration and the termination criterion.

Use False Position method to find the root where the upper limit and lower limit will be taken as input.

## CSE 506 Lab 6

Practise #1 (Example 6.4)
If AX contains a negative number, put -1 In BX; if AX contains 0, put O In BX; if AX contains a positive number, put 1 In BX.·

```mov ax,0FFFBh
CMP AX,0
JL NEGATIVE
JE ZERO
JG POSITIVE
NEGATIVE:
MOV BX,-1
JMP END_CASE
ZERO:
MOV BX,0
JMP END_CASEPOSITIVE:
MOV BX,1
JMP END_CASE
END_CASE:
MOV AX,4CH
INT 21h
MAIN ENDP
END MAIN```

Practise #2 (example 6.5)
If AL contains I or 3, display “o”; if AL contains 2 or 4, Display “e”.

```CMP AL,1
JE ODD
CMP AL,3
JE ODD
CMP AL,2
JE EVEN
CMP AL,4
JE EVEN
ODD:
MOV DL,'o'
JMP DISPLAY
EVEN:
MOV DL,'e'
JMP DISPLAY:
DISPLAY:
MOV AH,2
INT 21h```

Practise #3 (example 6.6)
Read a character and if it is uppercase display it

``` MOV AH,1
INT 21H
CMP AL,'A'
JNGE NOT
CMP AL,'Z'
JNLE NOT
MOV DL,AL
MOV AH,2
INT 21h
NOT:```

Practise #4 (example 6.7)
Read a character. If it’s “y” or “Y”, display it; otherwise, terminate the program.

```MOV AH,1
INT 21H
CMP AL,'y'
JE THEN
CMP AL,'Y'
JE THEN
JMP ELSE
THEN:
MOV AH,2
MOV DL,AL
INT 21H
JMP EXIT
ELSE:
JMP EXIT
EXIT:```

Practise #5 (Example 6.9)
Write some code to count the number of characters In a input line.

```MOV DX,0
MOV AH,l
INT 21H
WHILE:
CMP ·AL, OOH ;CR?
JE END_WHILE ;yes, exit
INC DX ;not CR, increment count
JMP WHILE ;loop back;
END_WHILE:```

Problem #1
Write a program to display a “?”, read two capital letters, and dis-play them on the next line In alphabetical order.

Practise #6 (Example 6.10)

```MOV AH,l
repeat:
INT 21H
CMP AL,' '
JNE REPEAT```

Marut section 6.5

Submit Assignment 4[Lab 6 and 7] through this link

## EEE 306 Lab 5 : Taylor series sine and cosine

Write a program to find an estimate of any value of cos(x). You should take input the value of x in degree, the maximum number of iteration, and the minimum error requirement

Sample code

```#include<stdio.h>
#include<math.h>
int fact(int n)
{
if (n==1){return 1;}
return n*fact(n-1);
}
int main()
{
int i,j, iter, sign=1;
double x, es,ea, previous=1, approx=1, curr_approx;
scanf("%lf", &x);
x=(x/180)*3.141592654;
//printf("%lf\n", x);
scanf("%d", &iter);
scanf("%lf", &es);
for (i=1;i<iter;i++)
{
j=i*2;
curr_approx=(pow(x,j)/(fact(j)));
if (sign%2==1)
{
approx=approx-curr_approx;
}
else {approx=approx+curr_approx;}

ea=fabs(((approx-previous)/approx)*100);
previous=approx;
sign++;
printf("\n %lf\t %lf", approx, ea);
if (ea<es) break;

}

printf("\n%lf", approx);
}```

Write a program to find an estimate of any value of sin(x). You should take input the value of x in degree, the maximum number of iteration, and the minimum error requirement

Sample code

```#include<stdio.h>
#include<math.h>
int fact(int n)
{
if (n==1){return 1;}
return n*fact(n-1);
}
int main()
{
int i,j, iter, sign=0;
double x, es,ea, previous=0, approx=0, curr_approx;
scanf("%lf", &x);
x=(x/180)*3.141592654;
//printf("%lf\n", x);
scanf("%d", &iter);
scanf("%lf", &es);
for (i=1;i<iter;i++)
{
j=(i*2)-1;
curr_approx=(pow(x,j)/(fact(j)));
if (sign%2==1)
{
approx=approx-curr_approx;
}
else {approx=approx+curr_approx;}

ea=fabs(((approx-previous)/approx)*100);
previous=approx;
sign++;
printf("\n %lf\t %lf", approx, ea);
if (ea<es) break;

}

printf("\n%lf", approx);
}```

## Assignment

There is no assignment for this lab.