0% found this document useful (0 votes)
70 views2 pages

Matlab Code For Power Consumption

This Matlab code uses a matrix D to calculate the coefficients of a polynomial that approximates the power consumption values given in the vector y over the range of values in the vector x. It initializes D as a zero matrix, populates the first column with y values, then calculates coefficients for higher order terms by taking differences between elements. The coefficients are stored in A, and polyval is used to calculate power estimates at specific x values based on the polynomial.

Uploaded by

Viraj Parmar
Copyright
© © All Rights Reserved
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)
70 views2 pages

Matlab Code For Power Consumption

This Matlab code uses a matrix D to calculate the coefficients of a polynomial that approximates the power consumption values given in the vector y over the range of values in the vector x. It initializes D as a zero matrix, populates the first column with y values, then calculates coefficients for higher order terms by taking differences between elements. The coefficients are stored in A, and polyval is used to calculate power estimates at specific x values based on the polynomial.

Uploaded by

Viraj Parmar
Copyright
© © All Rights Reserved
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/ 2

Matlab Code for power consumption

>> x = 1:5

x=

1 2 3 4 5

>> y = [620 600 610 600 860]

y=

620 600 610 600 860

>> n = length(x)

n= 5

>> D = zeros(n,n)

D=

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

>> D(:,1)= y

D=

620 0 0 0 0

600 0 0 0 0

610 0 0 0 0

600 0 0 0 0

860 0 0 0 0

>> for j= 2:n

for i= j:n

D(i,j)= (D(i,j-1)- D(i-1,j-1))/(x(i)-x(i-j-1))

end

end

Array indices must be positive integers or logical values.

>> for j=2:n

for i=j:n
D(i,j)= (D(i,j-1)- D(i-1,j-1))/(x(i)-x(i-j+1));

end

end

>> D

D=

620.0000 0 0 0 0

600.0000 -20.0000 0 0 0

610.0000 10.0000 15.0000 0 0

600.0000 -10.0000 -10.0000 -8.3333 0

860.0000 260.0000 135.0000 48.3333 14.1667

>> A = D(n,n);

>> for k = n-1:-1:1

A = conv(A,poly(x(k)));

r = length(A);

A(r) = A(r)+ D(k,k);

end

>> A

A=

1.0e+03 *

0.0142 -0.1500 0.5608 -0.8650 1.0600

>> polyval(A,1.5)

ans = 589.8438

>> polyval(A,2.5)

ans = 612.3438

>> polyval(A,3.5)

ans = 597.3438

>> polyval(A,4.5)

ans = 664.8438

You might also like