0% found this document useful (0 votes)
73 views5 pages

Source Code Delete

This document is a MATLAB program that performs polynomial interpolation on a set of input data points. It begins by displaying information about the programmer and program. It then describes that the program will compute the equation of a function using direct polynomial interpolation on a table of x and y values. It provides instructions for using the program and entering data. The program then walks through inputting data points, revising the data if needed, and computing polynomial interpolations up to the nth order based on the input data. It offers options for automatic or manual selection of data points for each interpolation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views5 pages

Source Code Delete

This document is a MATLAB program that performs polynomial interpolation on a set of input data points. It begins by displaying information about the programmer and program. It then describes that the program will compute the equation of a function using direct polynomial interpolation on a table of x and y values. It provides instructions for using the program and entering data. The program then walks through inputting data points, revising the data if needed, and computing polynomial interpolations up to the nth order based on the input data. It offers options for automatic or manual selection of data points for each interpolation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

clc

clear
%(c) by Mr. Marco H. Garcia
disp('==============================FILE=VERSION==================================')
disp('PROGRAMMER: MR. MARCO H GARCIA, B.S.Ch.E. Student')
disp('Revised: MAY 11 2011')
disp('Revision: 004')
disp('FileName: directpolyinterpolation.m')
disp('THIS FILE WAS CREATED SOLELY BY THE PROGRAMMER')
disp('============================================================================')
disp('============================PROGRAM=DESCRIPTION=============================')
%Description
disp('Matlab will compute the function(ie. the equation) of a given table of values
using')
disp('direct polynomial interpolation')
disp('Provided the polynomial to be solved is in the form')
disp('y(x) = A0 + A1*x + A2*x^2 + A3*x^3 + .... + An * x^n')
disp('============================================================================')
disp('============================GENERAL=INSTRUCTIONS============================')
disp('When the program ask you a value or an option, enter ONLY NUMBER string')
disp('Follow the instructions patiently to avoid bug encounter and/or unreliable result')
disp('Make sure that the x values of the data are arranged in order')
disp('To terminate the program while its still running press CTRL + BREAK')
disp('DO NOT EDIT the program - its codes,syntax,comments,filename,etc.')
disp('============================================================================')
%Preparing to input the values
%Initial logical condition
format long
q=1;
p=1;
%For looping
while q==1
if p==1
datasize=input('Enter the number of data you want to input(each one has x and y
values) : ');
while ceil(datasize)~=floor(datasize) || datasize < 4
disp('----------------------------------------------------------------------------')
fprintf('The value %f that you have entered is invalid. ', datasize)
disp('
')
disp('It must be a positive integer greater than three(3)!')
datasize=input('Again, Enter the number of data you want to input(each one
has x and y values) : ');
end
disp('_____________________________________________________________________________')
for a=1:1:datasize
if a==1
disp('Please type your first values below.')
elseif a==2
disp('Please type your second values below.')
elseif a==3
disp('Please type your third values below.')
else
fprintf('Please type your %f th values below.', a)
disp('
')
end
%The x value
m(a,1)=input('
Enter the value of x:');

%The y value
m(a,2)=input('

its the corresponding y value:');


end
else
end
disp('_____________________________________________________________________________')
disp('BELOW IS YOUR DATA')
disp('
')
%Displaying input
disp('value of x
/ value of y')
disp(m)
disp('_____________________________________________________________________________')
%Revising the input
disp('Based on the values above, would you like to revise the data?')
disp('Select the option for revising the data.')
disp('OPTION 1 : No, let my table of values be evaluated')
disp('OPTION 2 : Yes, I want to revise a portion of the table')
disp('OPTION 3 : Yes, I want to add values')
disp('OPTION 4 : Yes, I want to delete a portion of the table')
disp('OPTION 5 : Yes, let my table be removed - I want to start another table')
revoption=input('Please type the NUMBER of your option : ');
while revoption~=1 && revoption~=2 && revoption~=3 && revoption~=4 &&
revoption~=5
disp('----------------------------------------------------------------------------')
fprintf('The value %f that you have entered is invalid', revoption)
disp('
')
disp('Again, Select the option for revising the data.')
disp('OPTION 1 : No, let my table of values be evaluated')
disp('OPTION 2 : Yes, I want to revise a portion of the table')
disp('OPTION 3 : Yes, I want to add values')
disp('OPTION 4 : Yes, I want to delete a portion of the table')
disp('OPTION 5 : Yes, let my table be removed - I want to start another
table')
revoption=input('Again, Please type the NUMBER of your option : ');
end
disp('_____________________________________________________________________________')

%Managing Revision
switch revoption
case 1
q=0;
case 2
q=1;
p=0;
disp('Please select the location of the values you want to edit.')
aa=input('At what specific row? : ');
while ceil(aa)~=floor(aa) || aa > datasize || aa <= 0
disp('----------------------------------------------------------------------------')
fprintf('The value %f that you have entered is invalid. ', aa)
disp('
')
disp('It must be a positive integer not greater than the existing row!')
aa=input('Again, At what specific row? : ');
end
disp('----------------------------------------------------------------------------')
m(aa,1)=input('Enter the value of x at that specific row: ');
m(aa,2)=input('Enter its y value: ');

case 3
q=1;
p=0;
datasize=datasize+1;
a=datasize;
%The x value
m(a,1)=input('
Enter the value of x:');
%The y value
m(a,2)=input('
its the corresponding y value:');
case 4
q=1;
p=0;
disp('Please select the location of the values you want to delete.')
ab=input('At what specific row? : ');
while ceil(ab)~=floor(ab) || ab > datasize || ab <= 0
disp('----------------------------------------------------------------------------')
fprintf('The value %f that you have entered is invalid. ', ab)
disp('
')
disp('It must be a positive integer not greater than the existing
row!')
ab=input('Again, At what specific row? : ');
end
m(ab,:)=[];
datasize=datasize -1 ;
case 5
q=1;
p=1;
m=0;
end
end
disp('_____________________________________________________________________________')
n=datasize;
%Selecting the values to be used in each interpolation
disp('Selecting the values to be used in each interpolation is important')
disp(' ... especially when it comes to initial value conditions!')
disp('Please select an option:')
disp('OPTION 1 : AUTOMATICALLY SELECTING THE VALUES IN ORDER')
disp(' ... Matlab will automatically set the first row od the table as the starting value
for each interpolation')
disp(' ... for example, for linear interpolation, the 1st row and the second row will be
used')
disp('OPTION 2 : MANUALLY SELECT THE VALUES FOR EACH INTERPOLATION')
disp(' ... Choose the row interval in selecting the values for each interpolation ')
disp(' ... for ex. , for linear interpol., you can choose 1st row & 2nd, or 2nd &third,
or 3rd &4th, and so on.')
selectvalue=input('Enter the NUMBER of your option : ');
while selectvalue~=1 && selectvalue~=2
disp('----------------------------------------------------------------------------')
fprintf('The value %f that you have entered is invalid', selectvalue)
disp('
')
disp('Again Please select an option:')
disp('OPTION 1 : AUTOMATICALLY SELECTING THE VALUES IN ORDER')
disp(' ... Matlab will automatically set the first row od the table as the
starting value for each interpolation')
disp(' ... for example, for linear interpolation, the 1st row and the second
row will be used')
disp('OPTION 2 : MANUALLY SELECT THE VALUES FOR EACH INTERPOLATION')
disp(' ... Choose the row interval in selecting the values for each
interpolation ')

disp(' ... for ex. , for linear interpol., you can choose 1st row & 2nd, or
2nd &third, or 3rd &4th, and so on.')
selectvalue=input('Enter the NUMBER of your option : ');
end
disp('_____________________________________________________________________________')

%Evaluating the table of values


disp('Below is the computatation for nth order polynomial interpolation :')
switch selectvalue
case 1
for i =1:1:datasize-1
if i==1
disp('FOR LINEAR INTERPOLATION')
elseif i==2
disp('FOR QUADRATIC INTERPOLATION')
elseif i==3
disp('FOR CUBIC INTERPOLATION')
else
fprintf('FOR %f NTH ORDER INTERPOLATION', i)
disp('
')
end
for j = 1:1:i+1
for k=1:1:i+1
B(j,k)=m(j,1)^(k-1);
end
C(j,1)=m(j,2);
end
A=inv(B)*C
disp('----------------------------------------------------------------------------')
end
case 2
for i =1:1:datasize-1
if i==1
disp('FOR LINEAR INTERPOLATION')
elseif i==2
disp('FOR QUADRATIC INTERPOLATION')
elseif i==3
disp('FOR CUBIC INTERPOLATION')
else
fprintf('FOR %f NTH ORDER INTERPOLATION', i)
disp('
')
end
disp('This order of interpolation might not be needed')
disp('Please select an option : ')
disp(' OPTION 1 : LET ME PROCEED ')
disp(' OPTION 2 : SKIP THIS PART - PROCEED TO HIGHER ORDER INTERPOLATION')
ask_proceed=input('Please enter the NUMBER of your choice : ');

while ask_proceed~=1 && ask_proceed~=2


disp('----------------------------------------------------------------------------')
fprintf('The value %f that you have entered is invalid', ask_proceed)
disp('
')
disp('Please select an option : ')
disp(' OPTION 1 : LET ME PROCEED ')
disp(' OPTION 2 : SKIP THIS PART - PROCEED TO HIGHER ORDER INTERPOLATION')
ask_proceed=input('Please enter the NUMBER of your choice : ');
end
switch ask_proceed
case 1
disp('Select the values for this type of interpolation')
s=input('From row number : ');
t=input('Up to row number : ');
%Managing expected error
while t <= s || s > datasize - i || ceil(s)~=floor(s) ||
ceil(t)~=floor(t) || s<=0 || t<=0 || (t-s)~=i
disp('----------------------------------------------------------------------------')
disp('The values you entered are invalid!')
disp('Make sure that what you have entered fits the number of desired
points for the interpolation')
disp('Again, Select the values for this type of interpolation')
s=input('From row number : ');
t=input('Up to row number : ');
end
for j = s:1:t
for k=1:1:i+1
B(j-s+1,k)=m(j,1)^(k-1);
end
C(j-s+1,1)=m(j,2);
end
A=inv(B)*C
case 2
end
disp('_____________________________________________________________________________')
end
end

%Ending the program


disp('============================================================================')
disp('============================END OF THE PROGRAM==============================')

You might also like