using Plots using PyFormattedStrings T = [ 500.0, 650, 800, 950, 1100, 1250, 1400, 1550, 1700, 1850, 2000] R = [5.06898064e-06, 9.49169460e-05, 5.91159348e-04, 2.78345192e-03, 4.88059454e-03, 1.62306334e-02, 3.57378985e-02, 2.30324885e-02, 8.40528066e-02, 1.07758145e-01, 6.39353585e-02]; ##################### SOLUTION m = length(T) #--------- form y and x data y = log.(R) x = 1 ./T #--------- form vector b and matrix A, along with bhat and Ahat b = copy(y) f_1 = ones(m) f_2 = -x A = [f_1 f_2] bhat = A' * b Ahat = A' * A #--------- solve for η and recover parameters η = Ahat \ bhat lnk = η[1] E = η[2] k = exp(lnk) println(f"Optimal parameters: k={k:.3f}, E={E:.0f}") #-------- plot the model curve versus the data points TT = LinRange(minimum(T), maximum(T), 1000) # lots of T RR = k*exp.(-E./TT) # model R scatter(T, R, label="data") plot!(TT,RR, label="fitted model", lw=2) plot!(xlabel="T", ylabel="R") plot!(legend_foreground_color=nothing) x = T y = R #---------------- b = y f_1 = x.^4 f_2 = x.^3 f_3 = x.^2 f_4 = copy(x) f_5 = ones(length(x)) A = [f_1 f_2 f_3 f_4 f_5] bhat = A' * b Ahat = A' * A #---------------- η = Ahat \ bhat a,b,c,d,e = η #---------------- TT = LinRange(minimum(T), maximum(T), 1000) # lots of T RR = a*TT.^4 .+ b*TT.^3 .+ c*TT.^2 .+ d*TT .+ e scatter(T, R, label="data") plot!(TT,RR, label="fitted model", lw=2) plot!(xlabel="T", ylabel="R") plot!(legend_foreground_color=nothing)