[Scilab-users] horner test
Rafael Guerra
jrafaelbguerra at hotmail.com
Thu Oct 27 20:23:15 CEST 2016
(note: votre message n'a pas été publié)
Bonsoir,
Essayez le code suivant svp:
// START OF CODE
clear;
clf;
M = [
0.003 170000
0.0028 208980
0.0026 261261
0.0024 336000
0.0022 439530
0.002 570000
0.0018 785568
0.0016 1110375
0.0014 1667952
0.0012 2646000
0.001 4500000
0.0008 8812500
0.0006 20875000
0.0004 70500000 ];
x = M(:,1);
y = M(:,2);
function f = fmodel(a,x)
f = exp(a(1) + a(2)*x + a(3)*x.^a(4));
endfunction
function f = costfun(a,x,y)
f = norm(y - fmodel(a,x));
endfunction
a0 = [0;0;0;0];
[f,aop]= optim(list(NDcost,costfun,x,y),a0);
str = sprintf("Scilab''s optim result: y = %.4f*exp(%.2f*x
%+.2f*x^%+.2f)\n",exp(aop(1)),aop(2),aop(3),aop(4));
plot(x,y,"*r",x, fmodel(aop,x),"blue")
h = gca();
h.title.text= str;
h.title.font_size = 4;
xgrid
printf("\nEquation to model data: y = a1*exp(a2*x + a3*x^a4)\n")
printf("%s\n",str)
printf("Cost function value = %g",f)
// NOTE: the cost function value can be further reduced by fixing
a(4)=-0.021;
// and inverting for only 3 parameters: a(1), a(2) and a(3)
// END OF CODE
Cordialement,
Rafael
--
View this message in context: http://mailinglists.scilab.org/horner-test-tp4034828p4034875.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
More information about the users
mailing list