Find the roots of the polynomial

Assignment Help MATLAB Programming
Reference no: EM13973203

There will be two parts to the exam. A written part and a Matlab part. The written part will dictate the percentage of the Matlab part in scoring. The written part is closed book closed notes. The Matlab part is open book open notes. All the material covered in class and presented in the class notes is included in the material that will be tested. The notes are posted in Black Board under course documents.

When studying for the test understand how each and every line in the notes computes the final answer to the problem. Try and type these solutions on your own without looking at the solution. Solve additional problems from the text book on your own. Make sure you come to class regularly and do the work assigned to get the extra credit that has been offered.

Randi(10,5) generates an 2x2 matrix of random numbers from 1 to 10 challenge problem: Create a guessing game that where your group picks a number and its address in a random 5x5 matrix of integrs from 1 to 10. the program should give the correct answer and state whether the group wins or looses

Question 1:

Clear erases the memory;clc erases the screen

The '%' symbol comments out the line Notice that comments are in green 5+2 notice that the ans = 7 in the command window once the 'play' button on the top is clicked; the '+' operator adds the two numbers; the '-' operator subtracts the second 5-2 number from the first 5*2 '*' multiplies the two numbers 5/2 '/' divides the first by the second 5^2 '^' applies the second number as an exponent to the first Arithmetic operators are given preference in this order

Parenthesis are given the highest preference

(5+2)/2
5+2/2

Variable may be used where applicable in programming

Consider 5+2=7; there are three values in this equation

These are 5, 2 and 7. Each of these numbers can be represented by a variable name of your choice, eg:

x1=5 % x1 represents 5
y1=2 % y1 represents 2
z1=x1+y1 % z1 takes the value of 7

It is standard practice in programming to use variables Variables can be any name of your choice but preferably alphanumeric, say x1, y1 or z1; These variables are unique. There are standard available functions in Matlab such as Trigonometric functions

A function in matlab has a name and arugument(s); example y2=sind(30)% y2 is a variable, sind is the name of the function and 30 is the argument (within the parenthesis)

To know how to use the various functions google them clear
clc
A ';' after an expression or equation suppresses printing it can also be used to separate equations on the same line x1=3;% Notice that the ';' suppresses the printing after play

{
y1=2
z1=2*x1+3*y1
z2=2*x1/(3*y1)
z3=2*x1^2+3*y1^2
z4=(2*x1)^2+(3*y1)^2
z5=2*x1+3*y1+5*(x1+y1)/2
z6=2/x1+3/y1+x1^3
z7=5*x1/(7*y1)+2
z8=8*(3*x1+2*y1)
z9=(14*x1+17*y1)/3
z10=(5+x1)/(7*y1)+2
}
x2=[2,3,4,5];
x3=[-1,1,1,-1,-1];
y3=[-1,-1,1,1,-1];
figure(1), plot(x3,y3,-10,-10,10,10)
for i=1:10
disp('HELLO')
end
for i=-5:0.5:5
figure(1), plot(x3+i,y3+i,-10,-10,10,10)
pause(0.5)
end

Chalenge move the box on a diagonal line also, move the box on a circle of raduis 1

Do problems all the odd problems from page 33 to page 37. Home work will not be checked 

But will be discussed if there are questions them in class

Question 2:

Input Segment ( This segment should have all the known values) R1=0.08206; %(Notice that these given values are inserted as T1=273.2; % variables that have been assigned these values. V1=22.41; % The assignment is done by the '=' sign)
n1=1
a1=6.49;
b1=0.0562;
Main Segment (This is the part that programs the equations)
P1=n1*R1*T1/V1;
P2=n1*R1*T1/(V1-n1*b1)-a1*n1^2/V1^2
Output Segment ( This segment contains the results)
disp('This is the value of the pressure using P = nRT/V')
P1

Finding the roots of a polynomial

Find the roots of the polynomial y=x^2+3x+2

The polynomial is entered as: y=[1,3,2] % Notice thst 1,3,2 are the coefficients of Roots_y=roots(y) % the terms in the polynomial in decending order of the power of each term

Do problem 26 on page 37

Input Segment
b1=180;
b2=165;
c1=115;
A1=120;
A2=100;

Main Segment
a2=b1^2+c1^2-2*b1*c1*cosd(A1);
p1=[1,-2*b2*cosd(A2),b2^2-a2];
c2=roots(p1);

Output Segment
for i=1:2
if c2(i)>0
disp(' ')
disp(['The value of c2 is:',num2str(c2(i))])
else
% disp(' ')
% disp([num2str(c2(i)), 'is not the value of c2:'])
end
end
% Predefined constants
pi
exp(1)
1i

Functions are predefined (an interesting one is sound) y2=10*cosd([0:72000]);
sound(y2,110000)

Challenge question use a for loop to create the sound of a motor cycle and use it with the box that went on the track

Question 3:

One and Two Dimensional Arrays

A one dimensional array appears as: x1 = [1,2,5,7,3];

In this case x1 is the name of the variable 1,2,5,7,3 are the values assigned to x1 The value 7 can be used in Matlab by tying x1(4)

Two dimensional arrays consist of more than one

One Dimensional array; such as: x2 = [1,2,4,6,1;2,3,1,5,9]% The semi colon after the '1' moves the 2,3,1,5,9 to the next row below

In this case x2 is the name of the variable

The value 3 can be used in Matlab by typing?

x2(2,2)% The (2,2) stands for second row second column

Arrays can be created by three methods a) Tying them b)Using a range variable command;c) Programming

Note b) can be used for equispaced data only Example a) x3=[2,4,7,8] Example b) x4=0:0.5:4% 0 is the starting value;4 is the ending value
and 0.5 is the step size

Example c) for i=1:4 x5(i)=i^2; end x5

Create the two dim array x6=[1,2,3;4,5,6] by methods a,b,c x6_1=[1,2,3;4,5,6] % a) x6_2=[1:1:3;4:6] % b) ; since 1 is the step size it is not required for i=1:3

x6_3(1,i)=i;

x6_3(2,i)=i+3; end

Go through the definitions in Table 2.1-1 on page 45 logspace(1,100,2) linspace(1,9,10)

Find the max value, and its address, in x6

x6=[1,10,3;4,5,6]; [x7,k1]=max(x6);

[max_x6,k2]=max(x7);

disp(['The max value is ',num2str(max_x6)])

disp(['The address is: (',num2str(k1(k2)),',',num2str(k2),')'])

To get just the max value type:  max_6=max(max(x6))% This is known as nesting of functions
disp('HELLO')

Do TYU on page 47

Do problem 3 on page 96 randi(10,5)% Generates a 5X5 matrix of random numbers from 1 to 10

Challenge problem: Crete a guessing game where your group picks a number and its address in a random 2X2 matrix of integrs from 1 to 100.

The program should give the correct answer and state whether the group wins or looses

Refine your program so that the numbers are not repeated in the matrix

The input statement interactively assigns a value to a variable, ex guess=input('Enter the Guess value ')

Question 4:

Creating New Matrices from Existing Ones

A=[1,2,3,4;5,6,7,8;9,10,11,12]

If a new matrix is to be created using row 2 and 3 It can be created as:

B=[A(2:3,:)]% The 2:3, in the row address location is the range of the rows included; and the ':' includes all the column elements

Create a new matrix from A using columns 1, 2, and 3 C=[A(:,1:3)]% The ':' is for all the row elements

Create a new matrix D from A using columns 1,2,3, and 4 D=A

A=[3,7,-4,12;-5,9,10,2;6,13,8,11;15,5,4,1]

5 a)  V1=A(:,2)

6 c) D1=A(1:2,2:4) Includes all the elements within row 1,2 and col 2,3,4

Matrix Operations and Operators

Addition:

Any two matrices that have number of rows and columns can be added with a '+' sign between the matrix names

Example

A2 = [1,2;3,4] Has two rows and two columns, and

B2= [5,6;7,8] Has two rows and two columns thus they can be added

C2 = A2+B2 % Each element of A2 is added to that of B2

Note A2 and B2 have the same size, ie:2 rows and 2 columns

Subtraction is done in a similar way by using '-' for '+'

Multiplication of two matrices: THERE ARE TWO TYPES

a) Element by Element (scalar), and b)Matrix multiplication

a) In element by element the two matrices (or vectors), each  element from the first matrix (or vector) is multiplied by a corresponding element of the second matrix (or vector). This operation is implemented by placing a '.*' between the two matrices (or vectors);

Ex: C3=A2.*B2 % C3=[1*5,2*6;3*7,4*8]

The second type of multiplication is:

b) Matrix Multiplication: In this case, one has to ensure that the number of columns of first matrix (or vector) should equal the number of rows of the second matrix (or vector). The resultant matrix will have the dimension (number of rows of the first times nuber of columns of the second.This operation is implemented by placing a '*' between the two matrices (or vectors).

Ex: C4=A2*B2 % Observe that the number of columns of A2 = number of rows of B2; and the resultant C4 has 2 rows and 2 columns

In this case C4=[(1*5+2*7),(1*6+2*8);(3*5+4*7),(3*6+4*8)]

Verify these numbers by hand

Consider the vector Rx=[0,1]and Ry = [0,0]

Rx=[0,1];Ry=[0,0] figure(1), plot(Rx,Ry,-2,-2,2,2)

Also consider the rotational Matrix R given by:

R=[cosd(60),-sind(60);sind(60),cosd(60)]% Size equals (2X2)

Now consider the multiplication of each pair of numbers from

Rx and Ry with R as:

Temp=R*[Rx(1);Ry(1)];
Rx(1)=Temp(1);
Ry(1)=Temp(2);
Temp=R*[Rx(2);Ry(2)];
Rx(2)=Temp(1);
Ry(2)=Temp(2);
pause(1)
figure(1), plot(Rx,Ry,-2,-2,2,2)

Work these numbers by hand and verify each step above Challenge problem create a clock using this information

Question 5:

Given x = [1,2,3,4], use two methods to create y=[1,4,9,16] without typing the elements of y by hand

x=[1,2,3,4]

y1=x.^2

y2=x.*x

Create y3=[1,4,9,16], using a for loop for i=1:length(x)

y3(i)=x(i)^2;

y4(i)=x(i)*x(i);

end

y3

y4

x2=[1,2,3;4,5,6]

Create y5=[1,4,9;16,25,36] using a for loop [m,n]=size(x2); m gives the number of rows and n the number of cols for i=1:n

y5(1,i)=x2(1,i)^2;

y5(2,i)=x2(2,i)*x2(2,i);

end

y5

Work by hand by substituting each i into the equations above HW:Create y5 by using m in the for loop above Create y6=[1,4;9,16] using two for loops

for i=1:m

for j=1:n

y6(i,j)=x2(i,j)^2; % or y6(i,j)=x2(i,j)*x2(i,j)

end

end

y6

Work by hand by substituting each i and j into the equation above

Given x+2y=4 and 2x+y=5; in matrix form is expressed as:

AX=B;where A=[1,2;2,1] and X=[x;y] and B=[4;5]

The solution is given by: X=inverse of A*B, as:

A=[1,2;2,1];

B=[4;5];

X=inv(A)*B % Note:x=X(1) and y=X(2); X is not equal to x

Polynomials are defined in matlab as the vector of its coefficients

Ex: y8=x^2 + 3x + 4 is typed as:

y8=[1,3,4]

Ex: y8=x^2 + 4 is typed as:
y8=[1,0,4]

Two polynomials can be multiplied using the conv function and; divided using the deconv function (Table 2.6-1,pg 87)

Do TYU on page 85 and 88.

Do problems 16,20, 35, 55, 56 and 57, ppg 96 - 119 Exam I is next week

Attachment:- pro.rar

Reference no: EM13973203

Questions Cloud

Examine your plan through a biblical framework : Research the ethical and regulatory issues involved in executing your IMC plan. Describe how you will navigate each of the identified issues. Examine your plan through a biblical framework
Exercise personal judgment : The accountant is bound to inform officials only if she stands to personally gain (make money) from knowledge of the illegal act. The accountant must exercise personal judgment; a clear-cut answer does not exist given the limited information provi..
What would be its price relative to the xy inc bond : If CD, Inc., has a bond with a 5.25% coupon and a maturity of 20 years but which was lower rated, what would be its price relative to the XY, Inc., bond? Explain.
Is kinetic energy conserved in all of the experiments : Is momentum conserved in all of the experiments? Please give a complete description with examples as needed supporting your response.
Find the roots of the polynomial : Find the roots of the polynomial - A written part and a Matlab part. The written part will dictate the percentage of the Matlab part in scoring. The written part is closed book closed notes.
Amount of outstanding checks : Sylvan Company wrote checks totaling $26,520 during October and $25,779 during November. $23,460 of these checks cleared the bank in October, and $26,330 cleared the bank in November. What was the amount of outstanding checks on November 30?
Conclusion regarding the firm payment behavior : a. Calculate the day's purchases outstanding for March, April, May, and June using quarterly purchases to calculate the average daily purchases. b. What is your conclusion regarding the firm's payment behavior?
What is his uncorrected near point : A nearsighted person has a near point of 12 cm and a far point of 17 cm. If the corrective lens is 2.0 cm from his eye, what lens power will enable this person to see distant objects clearly?(answer should be in diopters)
What is the speed of the electron as it strikes plate b : A pair of charged conducting plates produces a uniform field of 12,000 N/C directed to the right, between the plates. The separation of the plates is 40 mm. In the figure, an ELECTRON is projected from plate A, directly toward plate B, with an ini..

Reviews

Write a Review

 

MATLAB Programming Questions & Answers

  What is the minimum snr for a sinusoid in white noise

What is the minimum SNR for a sinusoid in white noise to be detectable using frequency domain techniques (Periodogram and Blackman-Tukey)? Do the results depend on frequency? Compute and plot separate correlation functions of white noise data and of ..

  Write a system program for bus arbiter

The bus arbiter is a device used in multi-master system with shared bus. It is used to allocate the control of the shared system bus to one master at a time depending priority.

  Develop matlab function for the fixed-point method

Develop your own Matlab function for the Fixed-point method. Use the estimated relative error as your stopping criterion. The first line of your function should be function

  A volume 10 in long 5in wide and 05 in thick is to be

a volume 10 in. long 5in wide and 0.5 in. thick is to be removed by face milling cutter that is 3in. diameter and has 6

  Write the matlab code for nested for loops

write the MATLAB code for 3 nested for loops. Use the same variable naming scheme as above, and have the following number of iterations

  Jacobian needed for newtons method

Write a Sci/Matlab function that returns the function values and the Jacobian needed for Newton's method .

  Approximate the solution to the above initial value problem

1. dydt te3t - 2y 0 le t le 1 y0 0approximate the solution to the above initial value problem usinga modified-euler

  Random number generator to create a symmetric matrix

Use a random number generator to create a symmetric matrix - without using built-in MATLAB commands, using the Power Method in combination with the Method of Deflation, obtain the eigen values & eigenvectors of the matrix

  The matlab language has the built-in ability

The MATLAB language has the built-in ability to perform mathematical operations on complex numbers. However there are times when it is useful to treat complex numbers as structures.

  Writing a matlab script to approximate exp(x)

writing a matlab script to approximate exp(x) at exp(.05) using ""Taylor series"" ""and"" a ""while loop"".

  Biomedical engineering matlab based problems

Write the governing equation for the situations you wish to solve identifying terms which will cancel or stay.

  Plot with three different shading scheme (one plot per each

create two vectors X and Y of values from (-pi) to pr with a spacing of pi/10. Define the vector Z as: Z=(sin(sqrt(x^2+y^2)))/sqrt(x^2+y^2)

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd