Thứ Năm, 28 tháng 3, 2019

Machine learning Curve fitting using MATLAB

here is the code for the data set we have taken.



>> clear;
close all;
Tx = [80: -20: -340];
alphay=[6.47  6.36 6.24 6.12 6.00 5.86 5.72 5.58 5.43 5.28 5.09 4.91 4.72 4.52 4.30 4.08 3.83 3.58 3.33 3.07 2.76 2.45];
alphay=1.e-6*alphay;
plot(Tx,alphay,'bo');


title('Thermal expansion cofficient of steel');
ylabel('cofficient\alpha');
xlabel('temperature(in F)');
>> coef1=polyfit(Tx,alphay,1)



coef1 =

   1.0e-05 *

    0.0009    0.6025

>> coef1=polyfit(Tx,alphay,2)

coef1 =

   1.0e-05 *

   -0.0000    0.0006    0.6015

>> coef1=polyfit(Tx,alphay,3)

coef1 =

   1.0e-05 *

    0.0000   -0.0000    0.0006    0.5998

>> pred1=polyval(coef1,Tx);
>> pred2=polyval(coef2,Tx);
Undefined function or variable 'coef2'.

Did you mean:
>> coef1=polyfit(Tx,alphay,1)

coef1 =

   1.0e-05 *

    0.0009    0.6025

>> coef2=polyfit(Tx,alphay,2)

coef2 =

   1.0e-05 *

   -0.0000    0.0006    0.6015

>> coef3=polyfit(Tx,alphay,3)

coef3 =

   1.0e-05 *

    0.0000   -0.0000    0.0006    0.5998

>> pred1=polyval(coef1,Tx);
>> pred2=polyval(coef2,Tx);
>> pred3=polyval(coef3,Tx);
>> [pred1; pred2; pred3]

ans =

   1.0e-05 *

  Columns 1 through 7

    0.6776    0.6588    0.6400    0.6213    0.6025    0.5837    0.5649
    0.6432    0.6342    0.6243    0.6134    0.6015    0.5886    0.5748
    0.6467    0.6357    0.6243    0.6123    0.5998    0.5866    0.5727

  Columns 8 through 14

    0.5462    0.5274    0.5086    0.4898    0.4711    0.4523    0.4335
    0.5599    0.5441    0.5273    0.5095    0.4907    0.4710    0.4502
    0.5581    0.5426    0.5264    0.5092    0.4910    0.4719    0.4517

  Columns 15 through 21

    0.4147    0.3960    0.3772    0.3584    0.3397    0.3209    0.3021
    0.4285    0.4058    0.3821    0.3574    0.3318    0.3052    0.2776
    0.4303    0.4078    0.3841    0.3592    0.3328    0.3052    0.2760

  Column 22

    0.2833
    0.2490
    0.2455

>> hold on
>> plot(tx,pred1)
Undefined function or variable 'tx'.

Did you mean:
>> plot(Tx,pred1)
>> plot(Tx,pred2,'r')
>> plot(Tx,pred3,'k--')
>> legend({'Data' 'Linear' 'Quadratic' 'Cubic'}, 'Location', 'Northwest')
>> hold off
>>

0 nhận xét:

Đăng nhận xét

Popular Posts

Được tạo bởi Blogger.

Featured Post

Portland Man Pleads Guilty to Cyberstalking and Anonymous Telephone Harassment

PORTLAND, Ore.—On June 24, 2019, Bob Ibenne Ugwa, 50, of Portland, pleaded guilty to cyberstalking and anonymous telecommunications harassme...

Nhãn