questions on matlab

Upload: naina

Post on 09-Jan-2016

20 views

Category:

Documents


0 download

DESCRIPTION

mechanical and electrical circuits coded on matlab

TRANSCRIPT

Winter Training Report

1.(a)WriteaFORloopbasedprogramcalledFinitegeometricseriesthat,forgivennandx,asinputs,determinesYn,calculateits%deviationfromYanddisplaysthesetworesults. (b)ModifythesolutionofPartainordertodeterminen,taking%deviationlimitasinputsothat%deviation(asinparta)isalwayslesserthanthespecified%deviationlimit. Given, Yn(x)=1+x+x2+x3+x4+..+xn1.

NOTE:mod(x)1)

disp ('error');

else

yn=(1-x^n)/(1-x); %yn=1 + x + x^2+ +x^n yinf=1/(1-x); %yn for n tends to infinity per_dev=(yinf-yn)/yinf * 100; % deviation of yn from yinf disp('% deviation');

disp(' ');

disp(per_dev);

disp('yn');

disp(' ');

disp(yn);end;

Output:enter the no of term 5

enter the term 0.5

% deviation

3.1250 yn

1.9375b)Code:

%find n

per_dev=input('enter %deviation limit');

x=input('enter the term');

if(abs(x)>1)

disp('error');

else

n=log(per_dev/100)/log(x); % per_dev = (x^n)*100 disp('n');

disp(' ');

disp(n);end;

Output: fgs

enter %deviation limit 3.125

enter the term 0.5

n

5

Conclusion: Sum of the geometric series has been obtained. Percentage deviation from the sum for infinite no of terms has been obtained.%deviation = 3.125 for n= 5 and x=0.52.Aunityamplitudesquarewavey(t)canbeapproximatedbythesumofasinwaveatsomefundamentalfrequencyanditsharmonics(Fourierseriesofasquarewave).

Writeanmfilesquarewavethatgenerateaunityamplitudesquarewavebyabovemethodforncyclesofsquarewaveatauserdefinedfrequencyf.Displaythissquarewaveinagraph.Useadequateno.ofsamplesinacyclesoasnottodistortthe waveform.Solution:Code: % square wave generation

f=input('frequency');

t=0:0.1:(f);

y=(sin(t)+(sin(3*t)/3)+(sin(5*t)/5)+(sin(7*t)/7)+(sin(9*t)/9)); plot(t,y);

Output:frequency 50

Conclusion: Square wave, having frequency 50Hz, has been obtained using sine waves till ninth harmonic. Gibbs effect has also been observed.

3.Sayyouaredraggingaheavydresseratconstantvelocityacrossthehorizontalfloorofyournewhostelroomasshowninfiguregivenbelow.TheforceyouareapplyingtothedresserhasamagnitudeFanditisdirectedatanangleabovethehorizontal.TheweightofthedresserisWandthecoefficientoffrictionbetweenitandtheflooris.Newtonslawcanbeusedtoshowthat

0F= / (sin + cos)

Or,expressingtheforceasafractionofthedressersweight,i.e.,F=F/W, where,

(a) Write a FOR loop based program called Dragging dresser that,for agiven calculatesFfrom=0to90in1increments,andthendisplaystheresultingarrayof Fvaluesonagraphaswellasinnumericform.

(b) Runaboveprogramwith=0.1,0.4,and=1.0anddeterminetheangleminat which F is smallest in each case.Solutiona)

Code:%dragging dresser

u=input('enter the coefficient friction');

for x=0:1:90

f=u/(u*sin(x*pi/180)+cos(x*pi/180));

c(x+1)=f;

end;

disp(' values of F` ');

disp(' ');

disp(c);

x=0:1:90;

plot(x,c);

title('force vs angle');

xlabel('angle');

ylabel('force');Output:DraggingDresserA

enter the coefficient friction 0.4

values of F`

Columns 1 through 9

0.4000 0.3973 0.3947 0.3923 0.3901 0.3880 0.3860 0.3841 0.3824

Columns 10 through 18

0.3809 0.3794 0.3781 0.3769 0.3758 0.3749 0.3740 0.3733 0.3727

Columns 19 through 27

0.3722 0.3718 0.3716 0.3714 0.3714 0.3715 0.3717 0.3720 0.3724

Columns 28 through 360.3729 0.3736 0.3743 0.3752 0.3762 0.3774 0.3786 0.3800 0.3815

Columns 37 through 45

0.3831 0.3849 0.3867 0.3888 0.3909 0.3933 0.3957 0.3983 0.4011

Columns 46 through 54

0.4041 0.4072 0.4105 0.4139 0.4176 0.4214 0.4255 0.4297 0.4342

Columns 55 through 63

0.4389 0.4438 0.4490 0.4545 0.4602 0.4663 0.4726 0.4792 0.4862

Columns 64 through 72

0.4936 0.5013 0.5095 0.5180 0.5271 0.5366 0.5466 0.5572 0.5684

Columns 73 through 81

0.5802 0.5927 0.6059 0.6200 0.6349 0.6507 0.6676 0.6856 0.7048

Columns 82 through 90

0.7253 0.7473 0.7709 0.7963 0.8237 0.8533 0.8854 0.9203 0.9583

Column 91

1.0000

b)

At =0.1

Output:enter the coefficient friction 0.1

minimum force0.0995

at =0.4

Output:enter the coefficient friction 0.1

minimum force

0.3714

at =1

Output:

enter the coefficient friction 0.1

minimum force

0.7071

Conclusion:Values of F were obtained for different values of coefficient of friction and angle of inclination. Minimum value of F= 0.0995 was obtained for = 0.1 at 6.4.(a)WriteaprogramcalledMeanofrandomarray,whichgeneratesanarrayof

100randomnumbersintherangeof0to1,andthendeterminesthemeanofthisarrayofnumbers.Displaythemean. (b)ItisexpectedthatthenominalvalueofMeanshouldbe0.500.RunMeanofrandomarrayNtimesinarow,whereN=10.Duetotherandommannerinwhichthearrayisgeneratedeachtime,youwillfindmostoftheMeanfallwithinarangegivenby0.500xwhatvaluedoyouobserveforx?Whatthenisobservedpercentfluctuationofthemeaninthisdataset,wherepercentfluctuationisdefinedas(x/0.500) 100? (c)AutomatethisprocesstakingNasinput.Whenrun,theprogramwilldeterminethemeanofa100elementarrayofrandomnumbersNtimes,andsavethesemeanvaluesinanNelementarray.Thefluctuationsofthemeancanthenbedefinedasthestandarddeviationofthisarrayofmeanvalues.Determineandnameitasfluctuationandshowiton commandwindow.Solution: a)

a=rand (1,100)

a =

Columns 1 through 16

0.0015 0.2195 0.3881 0.7244 0.7671 0.2407 0.0355 0.9523 0.5305 0.1604 0.3628 0.2776 0.5807 0.6409 0.1189 0.0313

Columns 17 through 32

0.4808 0.1541 0.9266 0.4122 0.4038 0.1532 0.8751 0.8773 0.0928 0.3326 0.6935 0.1709 0.3459 0.3651 0.3417 0.9154

Columns 33 through 48

0.1712 0.1934 0.9662 0.4610 0.7349 0.0868 0.2153 0.5706 0.3236 0.9573 0.5904 0.1201 0.2767 0.1457 0.7191 0.7551

Columns 49 through 64

0.8479 0.1609 0.4269 0.8017 0.2064 0.6569 0.2902 0.6858 0.3088 0.9427 0.2389 0.6988 0.1399 0.4452 0.6460 0.0851

Columns 65 through 80

0.5120 0.2492 0.3753 0.5897 0.9952 0.0384 0.2657 0.3022 0.2061 0.6337 0.7156 0.5355 0.0746 0.1534 0.6837 0.3338

Columns 81 through 96

0.8420 0.9480 0.7517 0.0272 0.7441 0.3368 0.8014 0.1669 0.6367 0.1432 0.8201 0.1785 0.1794 0.1517 0.4346 0.8800

Columns 97 through 100

0.4995 0.5680 0.0876 0.4440

b=mean(a)b =0.4475

b)

Code:

%random no

n=10;

for x=1:10

a = rand(1,100);

b= mean(a);

del_x = (b-0.500);

per_fluctuation=(del_x*100/0.5);

disp('% fluctuation');

disp(' ');

disp(per_fluctuation);

end;

Output:% fluctuation

4.6630

% fluctuation

0.2796

% fluctuation

0.8928

% fluctuation

-0.5915

% fluctuation

1.4153

% fluctuation

-0.8244

% fluctuation

1.8440

% fluctuation

-5.1838

% fluctuation

-0.8298

% fluctuation

-4.3358

c)

Code:

%random no

n=input('no of times');

for x=1:n

a = rand(1,100);

b= mean(a);

c(x)=b;

del_x = (b-0.500);

per_fluctuation=(del_x*100/0.5);

fluctuation(x)=per_fluctuation;

end;

disp('mean');

disp(' ');

disp(c);

disp('% fluctuation');

disp(' ');

disp(fluctuation);

Output:no of times 20

mean

Columns 1 through 9

0.5280 0.4675 0.5044 0.4783 0.4929 0.5010 0.5183 0.4549 0.4310

Columns 10 through 18

0.5121 0.5147 0.5219 0.5290 0.5409 0.5053 0.4343 0.5017 0.5270

Columns 19 through 27

0.4968 0.5285 0.1027 0.1032 0.1037 0.1042 0.1048 0.1054 0.1061

Columns 28 through 36

0.1068 0.1075 0.1083 0.1092 0.1101 0.1110 0.1120 0.1130 0.1141

Columns 37 through 45

0.1152 0.1164 0.1177 0.1190 0.1204 0.1219 0.1234 0.1251 0.1268

Columns 46 through 54

0.1286 0.1304 0.1324 0.1345 0.1367 0.1390 0.1414 0.1440 0.1467

Columns 55 through 63

0.1495 0.1526 0.1557 0.1591 0.1627 0.1665 0.1705 0.1747 0.1793

Columns 64 through 72

0.1841 0.1893 0.1948 0.2008 0.2071 0.2140 0.2214 0.2294 0.2380

Columns 73 through 81

0.2474 0.2577 0.2690 0.2814 0.2950 0.3102 0.3271 0.3461 0.3675Columns 82 through 90

0.3918 0.4198 0.4522 0.4902 0.5354 0.5899 0.6570 0.7416 0.8515

Column 91

1.0000% fluctuation

[5.5989 -6.5093 0.8889 -4.3385 -1.4232 0.2071 3.6540 -9.0230 -13.8096

2.4199 2.9443 4.3741 5.8013 8.1812 1.0600 -13.1343 0.3489 5.4012

-0.6430 5.7051]Conclusion:

Mean of 100 random values between 0 and 1 was obtained. Deviation of mean from 0.5 was obtained.5. Compute the Fourier spectrum of the following sum of the two sinusoid signals

Y (t) = A1sin(2f1t) + A2sin(2f2t)

Where f1= 10kHz and f2= 12kHz where sampling frequency f s= 40kHz.Solution: Code:

fs=40000;

ts=1/fs;

n=200;

t=[0:n-1]*ts;

x=sin(2*pi*10000*t)+sin(2*pi*12000*t);

nfft=2^nextpow2(n);

Xf=fft(x,nfft)/n;

f=fs/2*linspace(0,1,nfft/2+1);

plot(f,2*abs(Xf(1:nfft/2+1)))

ylabel('amplitude')

xlabel('frequency')

title('fourier spectrum')

Output:

Conclusion: The Fourier spectrum of y (t) has been obtained having peaks at 10 and 12 KHz.6. A tank system is represented by the following first-order differential equation:11.5dh/dt + h(t) = q(t)

Where h (t) is the liquid level and q (t) is the input flow rate in m3/min. (a) Develop a Laplace transform model for the system. (b) Use Simulink to find the response of h (t) to a step change of 1 m3/min, but where there is a slowly varying frequency on the input signal of amplitude 0.1 and frequency 0.05 Hz.

Solution:

a)

Code:a= [0, 0, 1];

b= [0, 11.5, 1];

y= tf (a, b)

Transfer function:

1

-------------11.5 s + 1b)

Output:

Conclusion:Liquid level was checked with time. Level increases till 20min then tries to remain constant.7. A Boeing 747-400 accelerates on the runway according to the following first order differential equation: dVt/dt = k1 k2 * Vt where dVt/dt is the rate of change of velocity as a function of time (in m/s-s), Vt is the aircraft speed in m/s and k1 and k2 are two constants that relate the acceleration of the vehicle as a function of speed. k1 is 3.2 (m/s-s) and k2 = 0.018 (1/second). Create a Simulink model to calculate distance and velocity travelled as a function of time for this aircraft.Solution:

Conclusion:

Velocity follows a square wave.

Distance follows a triangular wave.8. Design and simulate a second order high pass Butterworth filter.

Solution:

Code:R1= 19.89e3; R2 =3.97e3; R3 =994.72e6; C1 =0.01e-6; C2 =0.1e-6;

C3 = 0.1e-6;

w = 2*pi*800;

num = [(w^2*R1*R2*(C2)^2) 0 0];

den=[w*R1*R2*(C2)^2 2*(w^2)*R2*C2 1];

y = tf(num,den)

Transfer function:

19.95 s^2

------------------------------

0.003969 s^2 + 2.006e004 s + 1

bode (y)Output: 9. Calculate the range that a ball would travel when it is thrown with an initial velocity of v0of 20m/s at angle . Calculate this range for all angles between 0 and 90 in steps. Determine the angle that will result in the maximum range for the ball. Plot the trajectory of the ball for angles between 5 and 85 increments. Plot the maximum-range trajectory in a different colour and with a thicker line. Assume that there is no air friction.Solution: a)Code: v=20;

g=9.8;

max=0;

for i=0:90

range=v*v*sin(2*i*pi/180)/g;

if(max