當前位置:編程學習大全網 - 編程軟體 - matlab最小二乘法程序有道題需大家解答 x=19 25 31 38 44 y=19.0 32.3 49.0 73.3 97.8求形如y=a+bx^2中a,b

matlab最小二乘法程序有道題需大家解答 x=19 25 31 38 44 y=19.0 32.3 49.0 73.3 97.8求形如y=a+bx^2中a,b

x=[19,25,31,38,44];

y=[19.0,32.3,49.0,73.3,97.8];

fun1=inline('c(1)+c(2)*x.^2','c','x');

%擬合函數

c=lsqcurvefit(fun1,[0,0],x,y)

%求擬合系數

['y=',num2str(c(1)),'+',num2str(c(2)),'x^2']%擬合函數表達式

y1=c(1)+c(2)*x.^2;

%擬合函數表達式值

plot

(x,y,'b*',

x,

y1,'r-');%繪制x,y點與擬合函數,比較擬合程度

進行結果:

fun1

=

inline

function:

fun1(c,x)

=

c(1)+c(2)*x.^2

optimization

terminated:

first-order

optimality

less

than

options.tolfun,

and

no

negative/zero

curvature

detected

in

trust

region

model.

c

=

0.972578657321613

0.0500351242188565

ans

=

y=0.97258+0.050035x^2

  • 上一篇:ui界面設計怎麽切片教程
  • 下一篇:android獲取手機cpu並判斷是單核還是多核
  • copyright 2024編程學習大全網