Given ohms law that V=IR current should be linearly proportional to voltage in the ideal scenario. In this instance voltage does not exhibit a linear relationship given its small change in current. This exponential relationship can be plotted given the following data.
The built-in polyfit function was used to derive three different order of powers so that a comparison could be made. I liked how easy the polyval function was to use and implement with data points.
Set up parameters
-Matrix C, for defining current value
-Matrix V, for defining voltage value
Set up polyfit
-plug in previous matrixes to order of 1 for first estimation
-plug in previous matrixes to order of 3 for second estimation
-plug in previous matrixes to order of 7 for first estimation
Set up values for graph
-define linspace for graph from -3 to 3.
-plug in previous (order of 1 estimation)
-plug in previous (order of 3 estimation)
-plug in previous (order of 7 estimation)
Set up plot
x = [-2 , -1 , -0.5 , 0.5 , 1 , 2]';
y = [-637 , -96.5 , -20.5 , 20.5 , 96.5 , 637 ]';
c = x\y;
%backslash solver
x1 = linspace(-2.5,2.5);
x2 = 263*x1;
%line best fit (linear)
figure
plot(x,y,'o')
hold on
plot(x1,x2,'r')
hold off
Numerical approach (top graph)
The green dots are the points given in the table, the blue line to the order of 1 is the first linear regression estimation, and the red line to the order of 3 is the second linear regression estimation.
Alternative approach (bottom graph)
The linear estimation is in green, the poly estimation to the order of 7 is in blue and the poly estimation to the order of 3 is in red. I wanted to look at how much difference the order would affect the estimation. All three are similar, but only at the
Doing the linear regression by hand made it easy for understanding how the polyfit function worked in matlab. The polyfit made it hard to realize which order of power to use; whereas, the numerical method simultaneously solved for the best degree.
When the order of the polynomial increases, the curves, and concavity of the line best fit also change. In this problem, I switched from 7 to 3 in the degree of the polynomial and saw that the function was inversely proportional to the other after a certain domain was met. After the data, the curve with x^7 did not follow the pattern of the data like the x^3 did yet they both passed each point the same way. This small change can determine whether the system will work or not even if the data seems almost right. Without knowing the full scope of the data an estimation even if it seems accurate can be completely wrong.
Interpolation can be done for each point so that relationship can be better represented. A quadratic interpolation would also provide a better representation of the system if the data points are changing drastically.