Source Code Delete
Source Code Delete
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('
%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('_____________________________________________________________________________')