2. Sheet 1
1.4 )
Write a function-file that can be used to
calculate the equivalent resistance of n
parallel connected resistors
1.3 )
Write a function-file to obtain the dot
product and the vector product of two
vectors a and b
function [c,d] = trial1(a,b)
d = sum(a.*b);
i = (a(2)*b(3))-(a(3)*b(2));
j = (a(3)*b(1))-(a(1)*b(3));
k = (a(1)*b(2))-(a(2)*b(1));
c = [i,j,k];
end
>> x=[1,5,6];
>> y=[2,3,8];
>> [c d]=trial1(x,y)
c =
22 4 -7
d =
65
>>
function R = trial2(x)
n = length(x);
y = 0;
for i = 1:n
y = y+(1/x(i));
end
R = (1/y);
3. Sheet 1
end
>> r=[100,200,300,400,500];
>> trial2(r)
ans =
43.7956
>>
>> R=[1 2 3;2 3 6;3 6 7];
>> I=[1;2;6];
>> v=R*I
v =
23
44
57
>>
>> y=0.5+j*6+3.5*exp(j*0.6)+(3+j*6)*exp(j*0.3*pi)
y =
0.2979 +13.9300i
>>
1.5 )
The voltage V is given as V=RI, where R
and I are resistance matrix and I current
vector. Evaluate V
1.6 )
simplify the expression
y=0.5+j6+3.5ej0.6
+(3+j6)ej0.3π
4. Sheet 1
function [ y ] = fact( n )
y=1;
i =1;
for i=1:n
y=i*y;
end
end
>> x=fact(7)/(fact(3)*fact(4))
x =
35
>>
function [ a ] = tarea( x , y , z )
s =(x+y+z)/2;
a= sqrt(s*(s-x)*(s-y)*(s-z));
end
>> tarea(56,27,43)
ans =
563.4891
>> tarea(5,12,13)
ans =
30
>>
1.7 )
Write a function file to evaluate n factorial (i.e. n!);
1.8 )
Write a function to compute the area
given the sides of a triangle.
NAME: Ahmed El-morsy Abdel-hamid
Sec: 1
about me :)
THANK YOU