0% found this document useful (0 votes)
42 views

Basant Kumar Adm - No.-16je002220 SEMESTER-4th: Matlab Assignment No.-2 Name

This document contains the solutions to 7 MATLAB assignment questions asked of a student named Basant Kumar. Each question demonstrates MATLAB code and provides the output generated by running that code. Question 1 generates a graph of a quadratic equation. Question 2 plots the cosine and Taylor series approximations of cosine. The remaining questions demonstrate functions to calculate squares, print a message in a loop, perform matrix operations, and plot exponential-trigonometric functions.

Uploaded by

Basant Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Basant Kumar Adm - No.-16je002220 SEMESTER-4th: Matlab Assignment No.-2 Name

This document contains the solutions to 7 MATLAB assignment questions asked of a student named Basant Kumar. Each question demonstrates MATLAB code and provides the output generated by running that code. Question 1 generates a graph of a quadratic equation. Question 2 plots the cosine and Taylor series approximations of cosine. The remaining questions demonstrate functions to calculate squares, print a message in a loop, perform matrix operations, and plot exponential-trigonometric functions.

Uploaded by

Basant Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MATLAB ASSIGNMENT NO.

-2

Name- Basant Kumar

Adm.no.-16je002220

SEMESTER-4th

Question no.1

>> ezplot('y^2-4*x=0',[0 ,5],[-10,10]);

>> axis('equal');

On running this program the following graph is obtained,

Question no.2

>> x=0:0.1:2*pi;

>> y=cos(x);

>> z=1-(x.^2)./2+(x.^2)./24;

>> plot(x,y,'-r',x,z,'-b');
On running this program the following graph is obtained,

Question no.3
for i=1:10;
j=i^2;
disp(['Square of ',num2str(i),'is ',num2str(j)]);
end
On running this program ,the following output is obtained-

Square of 1is 1

Square of 2is 4

Square of 3is 9

Square of 4is 16

Square of 5is 25

Square of 6is 36

Square of 7is 49

Square of 8is 64

Square of 9is 81

Square of 10is 100

Question No.4
i=1;

while i<=10
disp('Sachin Tendulkar');
i=i+1;
end
On running this program, the following output is obtained-
Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Sachin Tendulkar

Question no.5
>>A = rand(10)
A =
0.7577 0.8235 0.4898 0.4984 0.9593 0.3500 0.2858 0.1299 0.6020 0.8258
0.7431 0.6948 0.4456 0.9597 0.5472 0.1966 0.7572 0.5688 0.2630 0.5383
0.3922 0.3171 0.6463 0.3404 0.1386 0.2511 0.7537 0.4694 0.6541 0.9961
0.6555 0.9502 0.7094 0.5853 0.1493 0.6160 0.3804 0.0119 0.6892 0.0782
0.1712 0.0344 0.7547 0.2238 0.2575 0.4733 0.5678 0.3371 0.7482 0.4427
0.7060 0.4387 0.2760 0.7513 0.8407 0.3517 0.0759 0.1622 0.4505 0.1067
0.0318 0.3816 0.6797 0.2551 0.2543 0.8308 0.0540 0.7943 0.0838 0.9619
0.2769 0.7655 0.6551 0.5060 0.8143 0.5853 0.5308 0.3112 0.2290 0.0046
0.0462 0.7952 0.1626 0.6991 0.2435 0.5497 0.7792 0.5285 0.9133 0.7749
0.0971 0.1869 0.1190 0.8909 0.9293 0.9172 0.9340 0.1656 0.1524 0.8173
>> 3*A
ans =
2.2732 2.4704 1.4693 1.4951 2.8779 1.0500 0.8575 0.3897 1.8059 2.4775
2.2294 2.0845 1.3368 2.8792 1.6416 0.5898 2.2716 1.7065 0.7889 1.6150
1.1767 0.9513 1.9389 1.0212 0.4159 0.7533 2.2612 1.4082 1.9622 2.9884
1.9664 2.8507 2.1281 1.7558 0.4479 1.8481 1.1413 0.0357 2.0676 0.2345
0.5136 0.1033 2.2641 0.6714 0.7725 1.4199 1.7035 1.0114 2.2445 1.3280
2.1181 1.3162 0.8281 2.2538 2.5222 1.0550 0.2276 0.4865 1.3516 0.3200
0.0955 1.1447 2.0391 0.7653 0.7628 2.4925 0.1619 2.3829 0.2515 2.8857
0.8308 2.2966 1.9653 1.5179 2.4429 1.7558 1.5924 0.9336 0.6869 0.0139
0.1385 2.3856 0.4878 2.0972 0.7306 1.6492 2.3375 1.5856 2.7400 2.3247
0.2914 0.5606 0.3570 2.6727 2.7878 2.7516 2.8020 0.4969 0.4571 2.4519
>> round(A)
ans =

1 1 0 0 1 0 0 0 1 1
1 1 0 1 1 0 1 1 0 1
0 0 1 0 0 0 1 0 1 1
1 1 1 1 0 1 0 0 1 0
0 0 1 0 0 0 1 0 1 0
1 0 0 1 1 0 0 0 0 0
0 0 1 0 0 1 0 1 0 1
0 1 1 1 1 1 1 0 0 0
0 1 0 1 0 1 1 1 1 1
0 0 0 1 1 1 1 0 0 1

Question no.6
>> ezplot('t','exp(-t/2)*sin(t)',[0,pi/2]);
On running this program, the following output is obtained

Question No.7
fplot(@(t) exp(-t/2)*cos(t),[0 pi/2]);
On running this program, the following output is obtained

You might also like