Challenge

Project - Data Handling and Interpolation

PROJECT :

SYNTAX -

clear all
clc
% READING THE EXCEL FILE TO LOAD THE DATA
VI = xlsread('VI.xlsx')
V = VI(:,1) % VOLTAGE VALUES
I = VI(:,2) % CURRENT VALUES
ir = -17.3:0.1:0.9; % RANGE TO PERFORM INTERPOLATION
InD1 = interp1(V,I,ir,'spline'); % PIECEWISE CUBIC SPLINE INTERPOLATION
InD2 = interp1(V,I,ir,'pchip'); % SHAPE-PRESERVING PIECEWISE CUBIC INTERPOLATION
subplot(121);
plot(V,I,'o',ir,InD1,'r','linewidth',2);grid;
title('PIECEWISE CUBIC SPLINE INTERPOLATION');
xlabel('Voltage - V(Volt)');
ylabel('Current - I(mAmp)');
legend('Data','spline Interpolation');
subplot(122);
plot(V,I,'o',ir,InD2,'k','linewidth',2);grid;
title('SHAPE-PRESERVING PIECEWISE CUBIC INTERPOLATION');
xlabel('Voltage - V(Volt)');
ylabel('Current - I(mAmp)');
legend('Data','pchip Interpolation');
% COMPUTING THE CURRENT VALUES FOR GIVEN VOLTAGES
VV = [-17.2 -17.1 -13.8 -13.5 -13.0 -12.5 -11 -9 -5.76 -6 -1 0.11 0.25 0.5 0.61];
II = interp1(V,I,VV);
V1 = VV' % GIVEN VOLTAGE VALUES
I1 = II' % COMPUTED CURRENT VALUES
% WRITE TO TEXT FILE
Line_1 = 'INTERPOLATION DATA';
Line_2 = 'VOLTAGE Vs. CURRENT';
label_1 = 'V (Volts)';
label_2 = 'I (mAmp)';
label_1 = 'V (Volt)';
fid = fopen('Voltage vs Current.txt','w+t');
fprintf(fid,'%s\n',Line_1);
fprintf(fid,'\n');
fprintf(fid,'%s\n',Line_2);
fprintf(fid,'\n');
fprintf(fid,'%s %s \n',label_1,label_2);
for i=1:length(VV)
fprintf(fid,'%g %g \n',VV(i),II(i));
end
fclose(fid);

OUTPUT -


VI =

-17.3000 -28.0000
-17.1000 -24.0000
-17.0000 -19.0000
-16.8000 -14.0000
-16.5000 -9.0000
-16.0000 -6.0000
-15.0000 -4.0000
-14.0000 -3.0000
-12.0000 -2.0000
-10.0000 -1.3000
-8.0000 -1.0000
-5.0000 -0.6000
-2.0000 -0.3000
-0.2000 -0.1000
0.0900 0
0.1900 0
0.2700 0
0.3900 0.0100
0.4300 0.0300
0.5000 0.1700
0.5500 0.4200
0.6000 1.2300
0.6200 1.9900
0.6500 3.9100


V =

-17.3000
-17.1000
-17.0000
-16.8000
-16.5000
-16.0000
-15.0000
-14.0000
-12.0000
-10.0000
-8.0000
-5.0000
-2.0000
-0.2000
0.0900
0.1900
0.2700
0.3900
0.4300
0.5000
0.5500
0.6000
0.6200
0.6500


I =

-28.0000
-24.0000
-19.0000
-14.0000
-9.0000
-6.0000
-4.0000
-3.0000
-2.0000
-1.3000
-1.0000
-0.6000
-0.3000
-0.1000
0
0
0
0.0100
0.0300
0.1700
0.4200
1.2300
1.9900
3.9100


V1 =

-17.2000
-17.1000
-13.8000
-13.5000
-13.0000
-12.5000
-11.0000
-9.0000
-5.7600
-6.0000
-1.0000
0.1100
0.2500
0.5000
0.6100


I1 =

-26.0000
-24.0000
-2.9000
-2.7500
-2.5000
-2.2500
-1.6500
-1.1500
-0.7013
-0.7333
-0.1889
0
0
0.1700
1.6100

>>

=================

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.