%%MATLAB code for finding coefficients for given data
clear all
close all
%All data
f=[2.122; 9.429; 23.57; 74.25; 6.286];
x1=[5;3;0.6;0.1;3];
x2=[10;1;0.6;2.0;1.8];
%log of all data
lg_f=log(f);
lg_x1=log(x1);
lg_x2=log(x2);
%in matrix form
for i=1:length(f)
A(i,1)=1;
A(i,2)=lg_x1(i);
A(i,3)=lg_x2(i);
b(i,1)=lg_f(i);
end
fprintf('A matrix is\n')
disp(vpa(A,3))
fprintf('b matrix is\n')
disp(vpa(b,3))
cc=A\b;
fprintf('The parameter a1=%f, c1=%f and
c2=%f\n',cc(1),cc(2),cc(3))
fprintf('\n\tHence the actual parameter a=%f, c1=%f and
c2=%f\n',exp(cc(1)),cc(2),cc(3))
fprintf('\tThe equation is
f=(%f)*x1^(%f)*x2^(%f)\n',exp(cc(1)),cc(2),cc(3));
fun=@(x1,x2) exp(cc(1))*x1^cc(2)*x2^cc(3);
%plotting the function and model
hold on
plot(f,'r*')
for i=1:length(x1)
ff(i)=fun(x1(i),x2(i));
end
plot(ff)
title('Plotting the function for given x1 and x2')
ylabel('f_simulated')
legend('Actual data','simulated model','location','best')
box on; grid on;
%%%%%%%%%%%%%% End of Code %%%%%%%%%%%
- t=an Tag First we have to linearize this equ to find parameter values a, and a by taking log on both ride we get log (f) a log (au (2) o dog(a) to login) & C2 log ker) Let al e log (a.) a log (+) 2 a, + e, log (ne) et le log (uzli furen data - in dod 6 dooko logna 2.122 0.752359 1.609437 2.3023 9.429 13 2.243990 1.0976122 25.55 T06 Toro 3,15991470.!0825 -0.5782562 74.25 toont 2.0 14.3044 3771 2,30258570-693147T 6.286 3 8 1 83 8324 1.0986122 0-5877866 7 Has in Matrin form Ti 609437 2.302.585 1098612 o - -0-5108256 -0.018256) T -2.302555 -0.6231471 I 1.0986022 0.5977860 1 to 75259 2.243750 13.159874 4-3079377 1838329 C2
%&MATLAB code for finding coefficients for given data clear all close all All data f=[2.122; 9.429; 23.57; 74.25; 6.286); x1=[5;3;0.6;0.1;3]; x2=( 10;1;0.6;2.0;1.8); log of all data lg_f=log(); lg_xl-log(xl); lg_x2=log(x2); in matrix form for i=1:length(f) Ali,1)=1; Ali,2)=lg_xl(i); A(1,3)=lg_x2(i); b(i,1)=lg_f(i); end fprintf('A matrix is \n') disp (vpa (A,3)) fprintf('b matrix is \n') disp (vpa (b, 3)) CC=A\b; fprintf('The parameter al=8f, cl=8f and c2=8f\n',cc(1),CC(2),CC(3)) fprintf('\n\tHence the actual parameter a=8f, cl=8f and c28f \n', exp(cc(1)),CC(2),cc(3)) fprintf('\tThe equation is f($f)*x1^(8)*x2*(&f) \n',exp (CC(1)), cc (2), CC (3)); fun= (x1,x2) exp(cc(1))*xl^cc(2) *x2cc(3); &plotting the function and model hold on plot(f,'r*') for i=1:length(x1) ff(i)=fun(xl(i), x2(i)); end plot(ff) title('Plotting the function for given xl and x2') ylabel('f_simulated') legend('Actual data','simulated model', 'location', 'best') box on; grid on; 88888888888888 End of Code $8888888888 A matrix is
[ 1.0, 1.61, 2.3) [ 1.0, 1.1, 0] [ 1.0, -0.511, -0.511) [ 1.0, -2.3, 0.693] [ 1.0, 1.1, 0.588) b matrix is 0.752 2.24 3.16 4.31 1.84 The parameter al-2.828693, cl=-0.712952 and c2=-0.368874 Hence the actual parameter a=16.923327, cl=-0.712952 and c2=-0.3688 74 The equation is f=(16.923327) **1*(-0.712952)*X2(-0.368874) Plotting the function for given x1 and x2 Actual data simulated model fimulated 1 1.5 2 2.5 3 3.5 4 4.5 5 Published with MATLAB® R2018a