up

Project One Report for MAE 185

 

By Nasser Abbasi. April 30, 2003.

 

Contents

Project One Report for MAE 185 1

Introduction 1

Example 1 2

example 2 3

Example 3 4

Program listing 7

 

 

 

Introduction

 

This page explains the work done for this project, and how to use the program. Then 2 examples are shown showing the output of the program. Then at the end the source code listing for the program is given.

 

A program was written to factor a polynomial of order up to 12 (the program should work for higher orders, but I have not tested it, so now it will only allow up to degree 12). The polynomial is factored into quadratic factors. The program uses the Bairstow algorithm. The program was written in MATLAB 6.5.

 

The program is delivered in the form of ONE matlab function (for ease of running). The file name is called nma_proj_1.m, this file is contained in the floppy attached to this report.

 

To run the program please follow these instructions:

 

  1. Copy the file called nma_proj_1.m from the floppy disk to your C:\MATLAB6p5\work folder. This is the work folder under your main MATLAB installation. The path shown above is the correct path for MATLAB 6.5. If you are using an older MATLAB, then the work folder will still be there, however the path will be under C:\MATLAB12\work or something similar to this. Please check your C:\ folder and look for the MATLAB folder to be sure of its name on your system.
  2. Once the file nma_proj_1.m is copied to the work folder of your MATLAB installation, then start MATLAB and from the matlab console type the following command

    nma_proj_1

  3. Now MATLAB will find the file and run the program. The program will then ask for the degree of the polynomial, then the coefficients to be entered.
  4. The program will next ask for initial values of r,s,and percentage error as explained in the specification sheet of the project.
  5. If more factorization remain, then the program will again ask for an initial r,s and percentage error to use for the next factorization. This process is reputed until the remaining polynomial is of degree 2 or less.
  6. Each new value of r and s after each iteration are outputted.

When the program is finished running, it will display the final results, which consist of the initial polynomial, and all the quadratic factors generated. For each quadratic factored, it will print next to it the number of iterations needed, along with the initial r,s used and the error percentage used.

 

To help illustrate the running of the program, the following is MATLAB output of running the program for 3 examples. The first example uses the example given in the textbook at page 68. The second used the HW#1 problem 7.5, and the third example I used a degree 12 polynomial.

 

 

Example 1

 

>> nma_proj_1

degree of polynomial? >4

Coefficent a0 ?  >3.3

Coefficent a1 ?  >0.5

Coefficent a2 ?  >2.3

Coefficent a3 ?  >-1.1

Coefficent a4 ?  >1

 

Input polynomial is:

3.300000  +0.500000 x  +2.300000 x^2  -1.100000 x^3  + x^4 

 

Input for round 1 of reduction

Initial value for r?  >-1

Initial value for s?  >-1

percentage error?  >0.01

 

Iteration= 1      r= -0.890309886866699  s= -1.063453025086079

Iteration= 2      r= -0.900024696322848  s= -1.100161308574414

Iteration= 3      r= -0.899999998585020  s= -1.099999999747730

Iteration= 4      r= -0.900000000000000  s= -1.100000000000000

 

Completed round 1 of quadratic factorization. Result is:

 

Q(x)= x^2 +0.900000 x +1.100000

f(x)= 3.000000  -2.000000 x  + x^2 

 

*******************************************

Reduction completed...... Displaying final results

 

f(x)=3.300000  +0.500000 x  +2.300000 x^2  -1.100000 x^3  + x^4 

 

Q(x)=(1.100000  +0.900000 x  + x^2  )

Initial R= -1

Initial S= -1

Error percentage= 0.010000

Number of Iterations= 4

 

Remaining polynomial = (3.000000  -2.000000 x  + x^2  )

 


 

example 2

 

 >> nma_proj_1

degree of polynomial? >4

Coefficent a0 ?  >5

Coefficent a1 ?  >-2

Coefficent a2 ?  >6

Coefficent a3 ?  >-2

Coefficent a4 ?  >1

 

Input polynomial is:

+5  -2 x  +6 x^2  -2 x^3  + x^4 

 

Input for round 1 of reduction

Initial value for r?  >-1

Initial value for s?  >-1

percentage error?  >0.001

 

Iteration= 1      r= -0.061538461538462  s= -0.169230769230769

Iteration= 2      r= 0.042709523712992   s= -0.828980044617199

Iteration= 3      r= 0.002922797682596   s= -0.999429846290281

Iteration= 4      r= -0.000000819911177  s= -0.999994768884341

Iteration= 5      r= 0.000000000002669   s= -0.999999999989700

Iteration= 6      r= -0.000000000000000  s= -1.000000000000000

Iteration= 7      r= -0.000000000000000  s= -1.000000000000000

 

Completed round 1 of quadratic factorization. Result is:

 

Q(x)= x^2 +0.000000 x +1.000000

f(x)= +5  -2 x  + x^2 

 

*******************************************

Reduction completed...... Displaying final results

 

f(x)=+5  -2 x  +6 x^2  -2 x^3  + x^4 

 

Q(x)=(+1  + x^2  )

Initial R= -1

Initial S= -1

Error percentage= 0.001000

Number of Iterations= 7

 

Remaining polynomial = (+5  -2 x  + x^2  )

 


Example 3

>> nma_proj_1

degree of polynomial? >12

Coefficent a0 ?  >1

Coefficent a1 ?  >2

Coefficent a2 ?  >3

Coefficent a3 ?  >4

Coefficent a4 ?  >5

Coefficent a5 ?  >6

Coefficent a6 ?  >7

Coefficent a7 ?  >8

Coefficent a8 ?  >9

Coefficent a9 ?  >10

Coefficent a10 ?  >11

Coefficent a11 ?  >12

Coefficent a12 ?  >13

 

Input polynomial is:

+1  +2 x  +3 x^2  +4 x^3  +5 x^4  +6 x^5  +7 x^6  +8 x^7  +9 x^8  +10 x^9  +11 x^10  +12 x^11  +13 x^12 

 

Input for round 1 of reduction

Initial value for r?  >0

Initial value for s?  >0

percentage error?  >0.001

 

Iteration= 1   r= -2.000000000000000 s= 1.000000000000000

Iteration= 2   r= 0.825264990699901  s= 7.820120074176667

Iteration= 3   r= 0.175037879019421  s= 8.455575565058147

Iteration= 4   r= 0.108551575900868  s= 7.107859063155462

Iteration= 5   r= 0.056317310407555  s= 5.955810320597949

Iteration= 6   r= 0.014261795471642  s= 4.978207257988730

Iteration= 7   r= -0.020334754977247 s= 4.152275589154630

Iteration= 8   r= -0.049451762666777 s= 3.456355545252901

Iteration= 9   r= -0.074654375038776 s= 2.870838277959082

Iteration= 10  r= -0.097309013780552 s= 2.378373566736430

Iteration= 11  r= -0.118773929907182 s= 1.963736429301029

Iteration= 12  r= -0.140634519934368 s= 1.613499283447184

Iteration= 13  r= -0.165084546806031 s= 1.315525787269822

Iteration= 14  r= -0.195660171797862 s= 1.058174688571575

Iteration= 15  r= -0.238822250888860 s= 0.828877896960668

Iteration= 16  r= -0.307611751610722 s= 0.611326347505578

Iteration= 17  r= -0.429453147777501 s= 0.380549475473609

Iteration= 18  r= -0.653562702271718 s= 0.101537953480983

Iteration= 19  r= -1.042327752355456 s= -0.259328618750492

Iteration= 20  r= -1.684353579089757 s= -0.709903565031315

Iteration= 21  r= -1.478014424618908 s= -0.520541326756370

Iteration= 22  r= -1.379729264590980 s= -0.457853305040554

Iteration= 23  r= -1.507621906983582 s= -0.606674213286386

Iteration= 24  r= -1.520105793615768 s= -0.609361528936925

Iteration= 25  r= -1.523428029397745 s= -0.613206542564281

Iteration= 26  r= -1.523437720381192 s= -0.613207947803701

 

Completed round 1 of quadratic factorization. Result is:

 

Q(x)= x^2 +1.523438 x +0.613208

f(x)= 1.630161  -0.789201 x  +4.194556 x^2  -2.610709 x^3  +7.799446 x^4  -5.334557 x^5  +11.949266 x^6  -7.940700 x^7  +14.918007 x^8  -7.804564 x^9  +13 x^10 


 

Input for round 2 of reduction

Initial value for r?  >0

Initial value for s?  >0

percentage error?  >0.001

 

Iteration= 1   r= -0.060868697879560 s= -0.400089662603514

Iteration= 2   r= 0.165200385901510  s= -0.852305916886219

Iteration= 3   r= 0.144067906879829  s= -0.725897316901379

Iteration= 4   r= 0.122949728990631  s= -0.660922375422594

Iteration= 5   r= 0.112643754024701  s= -0.647514098533939

Iteration= 6   r= 0.111816247426912  s= -0.647308220856163

Iteration= 7   r= 0.111815367720120  s= -0.647310104598319

 

Completed round 2 of quadratic factorization. Result is:

 

Q(x)= x^2 -0.111815 x +0.647310

f(x)= 2.518354  -0.784188 x  +2.454036 x^2  -2.397807 x^3  +7.843707 x^4  -3.181940 x^5  +5.792860 x^6  -6.350953 x^7  +13 x^8 

 

Input for round 3 of reduction

Initial value for r?  >0

Initial value for s?  >0

percentage error?  >0.001

 

Iteration= 1   r= -0.993273612465389 s= -1.343609645314211

Iteration= 2   r= -0.862726959803642 s= -1.010464551488198

Iteration= 3   r= -0.760691153617270 s= -0.785809073925186

Iteration= 4   r= -0.676367324652383 s= -0.656262617993335

Iteration= 5   r= -0.621346560219958 s= -0.623065852947570

Iteration= 6   r= -0.617197518816925 s= -0.628903082541705

Iteration= 7   r= -0.617359187239549 s= -0.628891034498867

Iteration= 8   r= -0.617359236961131 s= -0.628891110784295

 

Completed round 3 of quadratic factorization. Result is:

 

Q(x)= x^2 +0.617359 x +0.628891

f(x)= 4.004434  -5.177943 x  +2.617708 x^2  +1.850989 x^3  +6.492817 x^4  -14.376623 x^5  +13 x^6 

 

Input for round 4 of reduction

Initial value for r?  >0

Initial value for s?  >0

percentage error?  >0.001

 

Iteration= 1   r= 1.275590218768978  s= 0.993426366683489

Iteration= 2   r= 0.390464941011387  s= 2.116148542436314

Iteration= 3   r= 0.379706633048355  s= 1.351374439267144

Iteration= 4   r= 0.390993127837409  s= 0.796168522841744

Iteration= 5   r= 0.475457316467570  s= 0.315314307681220

Iteration= 6   r= 0.971497095004576  s= -0.360918743838894

Iteration= 7   r= 1.360144402844268  s= -0.732310559628934

Iteration= 8   r= 1.400763945747168  s= -0.647435361651808

Iteration= 9   r= 1.454784161781157  s= -0.735025742970578

Iteration= 10  r= 1.458420191572684  s= -0.734856406122465

Iteration= 11  r= 1.458484746017808  s= -0.734972183907004

Iteration= 12  r= 1.458484756905666  s= -0.734972187982800

 

Completed round 4 of quadratic factorization. Result is:

 

Q(x)= x^2 -1.458485 x +0.734972

f(x)= 5.448415  +3.766793 x  +3.623405 x^2  +4.583679 x^3  +13 x^4 


 

Input for round 5 of reduction

Initial value for r?  >0

Initial value for s?  >0

percentage error?  >0.001

 

Iteration= 1   r= -2.737727056192364 s= 1.342393392145367

Iteration= 2   r= 0.345250133572883  s= 10.571492457995895

Iteration= 3   r= 0.066800873437501  s= 5.429113384898056

Iteration= 4   r= -0.077030082836193 s= 2.674445827593081

Iteration= 5   r= -0.168727305987084 s= 1.222833050892130

Iteration= 6   r= -0.263181564191614 s= 0.409572553597078

Iteration= 7   r= -0.495517272834559 s= -0.216612600924056

Iteration= 8   r= -1.479722121926726 s= -0.176144490672537

Iteration= 9   r= -0.759878202012628 s= 0.511631194118970

Iteration= 10  r= -0.731410755432144 s= -0.073763304228732

Iteration= 11  r= -1.479191534725507 s= -0.927088868531243

Iteration= 12  r= -1.256359804222183 s= -0.655603778528051

Iteration= 13  r= -1.201218278462528 s= -0.616464217022750

Iteration= 14  r= -1.200254734645366 s= -0.618156388016141

Iteration= 15  r= -1.200263049200175 s= -0.618169676234394

Iteration= 16  r= -1.200263049092128 s= -0.618169676103302

 

Completed round 5 of quadratic factorization. Result is:

 

Q(x)= x^2 +1.200263 x +0.618170

f(x)= 8.813786  -11.019741 x  +13 x^2 

 

*******************************************

Reduction completed...... Displaying final results

 

f(x)=+1  +2 x  +3 x^2  +4 x^3  +5 x^4  +6 x^5  +7 x^6  +8 x^7  +9 x^8  +10 x^9  +11 x^10  +12 x^11  +13 x^12 

 

Q(x)=(0.613208  +1.523438 x  + x^2  )

Initial R= 0

Initial S= 0

Error percentage= 0.001000

Number of Iterations= 26

 

Q(x)=(0.647310  + x^2  )

Initial R= 0

Initial S= 0

Error percentage= 0.001000

Number of Iterations= 7

 

Q(x)=(0.628891  +0.617359 x  + x^2  )

Initial R= 0

Initial S= 0

Error percentage= 0.001000

Number of Iterations= 8

 

Q(x)=(0.734972  -1.458485 x  + x^2  )

Initial R= 0

Initial S= 0

Error percentage= 0.001000

Number of Iterations= 12

 

Q(x)=(0.618170  +1.200263 x  + x^2  )

Initial R= 0

Initial S= 0

Error percentage= 0.001000

Number of Iterations= 16

 

Remaining polynomial = (8.813786  -11.019741 x  +13 x^2  )

>> 

 


Program listing

nma_proj_1.m.txt

MAE146.m.txt