Langrage和Newton插值法的matlab实现.doc

上传人:wj 文档编号:1103697 上传时间:2023-04-30 格式:DOC 页数:11 大小:169.50KB
下载 相关 举报
Langrage和Newton插值法的matlab实现.doc_第1页
第1页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第2页
第2页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第3页
第3页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第4页
第4页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第5页
第5页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第6页
第6页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第7页
第7页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第8页
第8页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第9页
第9页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第10页
第10页 / 共11页
Langrage和Newton插值法的matlab实现.doc_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Langrage和Newton插值法的matlab实现.doc

《Langrage和Newton插值法的matlab实现.doc》由会员分享,可在线阅读,更多相关《Langrage和Newton插值法的matlab实现.doc(11页珍藏版)》请在冰点文库上搜索。

Langrage和Newton插值法的matlab实现.doc

仅供参考

1.已知数据如下:

0.2

0.4

0.6

0.8

1.0

0.98

0.92

0.81

0.64

0.38

(1)用MATLAB语言编写按Langrage插值法和Newton插值法计算插值的程序,对以上数据进行插值;

(2)利用MATLAB在第一个图中画出离散数据及插值函数曲线。

(1.1)langrage插值法编程实现

symsx

x0=[0.2,0.4,0.6,0.8,1.0];

y0=[0.98,0.92,0.81,0.64,0.38];

fori=1:

5

a=1;

forj=1:

5

ifj~=i

a=expand(a*(x-x0(j)));

end

end

b=1;

fork=1:

5

ifk~=i

b=b*(x0(i)-x0(k));

end

end

A(i)=expand(a/b);

end

L=0;

forp=1:

5

L=L+y0(p)*A(p);

end

L

L=

-25/48*x^4+5/6*x^3-53/48*x^2+23/120*x+49/50

(1.2)Newton插值程序实现

clearall

clc

symsx

x0=[0.2,0.4,0.6,0.8,1.0];

y0=[0.98,0.92,0.81,0.64,0.38];

fork=1:

5

fori=1:

k

a=1;

b=0;

forj=1:

k

ifj~=i

a=a*(x0(i)-x0(j));

end

end

b=b+y0(i)/a;

end

A(k)=b;

end

B=[1,(x-x0

(1)),(x-x0

(1))*(x-x0

(2)),(x-x0

(1))*(x-x0

(2))*(x-x0(3)),(x-x0

(1))*(x-x0

(2))*(x-x0(3))*(x-x0(4))];

L1=A.*B;

l=0;

form=1:

5

l=l+L1(m);

end

L=expand(l)

L=

61/100+13/30*x+383/48*x^2-155/24*x^3+475/48*x^4

(2)画图

x0=[0.2,0.4,0.6,0.8,1.0];

y0=[0.98,0.92,0.81,0.64,0.38];

subplot(1,2,1);

plot(x0

(1),y0

(1),'+r',x0

(2),y0

(2),'+r',x0(3),y0(3),'+r',x0(4),y0(4),'+r',x0(5),y0(5),'+r')

x=0:

0.05:

1;

y=-25/48.*x.^4+5/6.*x.^3-53/48.*x.^2+23/120.*x+49/50;

subplot(1,2,2);

plot(x,y)

2.给定函数,利用上题编好的Langrage插值程序(或Newton插值程序),分别取3个,5个、9个、11个等距节点作多项式插值,分别画出插值函数及原函数的图形,以验证Runge现象、分析插值多项式的收敛性。

取三个节点如下

clear

clc

x0=0:

0.5:

1;

y0=1./(1+25.*x0.^2);

symsx

fori=1:

3

a=1;

forj=1:

3

ifj~=i

a=expand(a*(x-x0(j)));

end

end

b=1;

fork=1:

3

ifk~=i

b=b*(x0(i)-x0(k));

end

end

A(i)=expand(a/b);

end

L=0;

forp=1:

3

L=L+y0(p)*A(p);

end

L

L=

575/377*x^2-1875/754*x+1

x1=0:

0.0001:

1;

y1=1./(1+25.*x1.^2);

y2=575/377.*x1.^2-1875/754.*x1+1;

plot(x1,y1,'+r')

holdon

plot(x1,y2,'*k')

取五个节点如下

clear

clc

x0=0:

0.25:

1;

y0=1./(1+25.*x0.^2);

symsx

fori=1:

5

a=1;

forj=1:

5

ifj~=i

a=expand(a*(x-x0(j)));

end

end

b=1;

fork=1:

5

ifk~=i

b=b*(x0(i)-x0(k));

end

end

A(i)=expand(a/b);

end

L=0;

forp=1:

5

L=L+y0(p)*A(p);

end

L

L=

1570000/3725137*x^4-9375000/3725137*x^3+16996575/3725137*x^2-25546875/7450274*x+1

x1=0:

0.0001:

1;

y1=1./(1+25.*x1.^2);

y2=1570000/3725137.*x1.^4-9375000/3725137.*x1.^3+16996575/3725137.*x1.^2-25546875/7450274.*x1+1;

plot(x1,y1,'+r')

holdon

plot(x1,y2,'*k')

取九个节点

clear

clc

x0=0:

0.125:

1;

y0=1./(1+25.*x0.^2);

symsx

fori=1:

9

a=1;

forj=1:

9

ifj~=i

a=expand(a*(x-x0(j)));

end

end

b=1;

fork=1:

9

ifk~=i

b=b*(x0(i)-x0(k));

end

end

A(i)=expand(a/b);

end

L=0;

forp=1:

9

L=L+y0(p)*A(p);

end

L

L=

-745631513600000000/6545742033698309*x^8+3419841600000000000/6545742033698309*x^7-6621592639456000000/6545742033698309*x^6+7019299350000000000/6545742033698309*x^5-4393156359065510000/6545742033698309*x^4+1603771386328125000/6545742033698309*x^3-22515465371294825/503518617976793*x^2+7750485791015625/13091484067396618*x+1

x1=0:

0.0001:

1;

y1=1./(1+25.*x1.^2);

y2=-745631513600000000/6545742033698309.*x1.^8+3419841600000000000/6545742033698309.*x1.^7-6621592639456000000/6545742033698309.*x1.^6+7019299350000000000/6545742033698309.*x1.^5-4393156359065510000/6545742033698309.*x1.^4+1603771386328125000/6545742033698309.*x1.^3-22515465371294825/503518617976793.*x1.^2+7750485791015625/13091484067396618.*x1+1;

plot(x1,y1,'--r')

holdon

plot(x1,y2,'k')

取十一个节点

clear

clc

x0=0:

0.1:

1;

y0=1./(1+25.*x0.^2);

symsx

fori=1:

11

a=1;

forj=1:

11

ifj~=i

a=expand(a*(x-x0(j)));

end

end

b=1;

fork=1:

11

ifk~=i

b=b*(x0(i)-x0(k));

end

end

A(i)=expand(a/b);

end

L=0;

forp=1:

11

L=L+y0(p)*A(p);

end

L

L=

-3424659989996187952765255410847243578373715179152933334243989076419413866221274679613493494711144683493498122577559208945836334877091233965270312991850496/53178433436436854112137751234603968902040519205586379256501744820282895654320795897063686873618885213871681425479462777404544150039401268463093187392345*x^10+121086192503439730397482523520885664132124539598838340051093380960893394307010980404143358507570389043992652515804277667665850493797050376702379508889550848/265892167182184270560688756173019844510202596027931896282508724101414478271603979485318434368094426069358407127397313887022720750197006342315465936961725*x^9-1866684313118720862370761857357873725727309899525470177959305327610184009984336016654604586537474647225602036909009509629462337871679343044326927998528782336/1329460835910921352803443780865099222551012980139659481412543620507072391358019897426592171840472130346792035636986569435113603750985031711577329684808625*x^8+2361180753817157490601164359984945296081740861682440608420596372826539195107329413948261865424198108462767092910060184301539989010355832103758391330174140416/949614882793515252002459843475070873250723557242613915294674014647908850970014212447565837028908664533422882597847549596509716964989308365412378346291875*x^7-457886048169006616129349621923130935315718577767591109706724078596021810685953146111998069361124151268468324505592802944898398657172353734910039192768610304/163726703929916422759044800599150150560469578834933433671495519766880836374140381456476868453260114574728083206525439585605123614653329028519375576946875*x^6+12088962400912270040146492926531809320957521999385477664676343065588318451013566108754284949808961761238168826983911041047393789416378273014456245169422336/5817292837500093432997181104355984276223496430057669169901213027737741062055955724378619437814926883934224960780737255553232767489520389398507586046875*x^5-94267425310773612599638740322629208595714990909621095965576142327181279246584265780378361930594498757706795149698078389699551522017848691472848705458783911936/92323669160480649500239151448965223788264790287476352875871084757435582733195826210180011933366120162971669141457400655216222482707293868859536783667265625*x^4+33750253531325596345124977498815779434900844255428881286847640207252938674043829294981084784890319038148035145537994507247102141432693715258453281704155021312/106527310569785364807968251671882950524920911870165022549082020873964133922918261011746167615422446341890387470912385371403333633893031387145619365769921875*x^3-121115835517746494394166199580632149437241601272999328914442173693156498884735106053392300700051676118679651553633528158918481769660983714572459994328070094848/2308091729012016237505978786224130594706619757186908821896777118935889568329895655254500298334153004074291728536435016380405562067682346721488419591681640625*x^2+302715481258614897028208818090865836694936458005708460532843137494564284294144717946752760785413468650273921187174271696035438592761935270935490270251188224/329727389858859462500854112317732942100945679598129831699539588419412795475699379322071471190593286296327389790919288054343651723954620960212631370240234375*x+217902164370694078464/217902164370694140625

x1=0:

0.0001:

1;

y1=1./(1+25.*x1.^2);

y2=-3424659989996187952765255410847243578373715179152933334243989076419413866221274679613493494711144683493498122577559208945836334877091233965270312991850496/53178433436436854112137751234603968902040519205586379256501744820282895654320795897063686873618885213871681425479462777404544150039401268463093187392345.*x1.^10+121086192503439730397482523520885664132124539598838340051093380960893394307010980404143358507570389043992652515804277667665850493797050376702379508889550848/265892167182184270560688756173019844510202596027931896282508724101414478271603979485318434368094426069358407127397313887022720750197006342315465936961725.*x1.^9-1866684313118720862370761857357873725727309899525470177959305327610184009984336016654604586537474647225602036909009509629462337871679343044326927998528782336/1329460835910921352803443780865099222551012980139659481412543620507072391358019897426592171840472130346792035636986569435113603750985031711577329684808625.*x1.^8+2361180753817157490601164359984945296081740861682440608420596372826539195107329413948261865424198108462767092910060184301539989010355832103758391330174140416/949614882793515252002459843475070873250723557242613915294674014647908850970014212447565837028908664533422882597847549596509716964989308365412378346291875.*x1.^7-457886048169006616129349621923130935315718577767591109706724078596021810685953146111998069361124151268468324505592802944898398657172353734910039192768610304/163726703929916422759044800599150150560469578834933433671495519766880836374140381456476868453260114574728083206525439585605123614653329028519375576946875.*x1.^6+12088962400912270040146492926531809320957521999385477664676343065588318451013566108754284949808961761238168826983911041047393789416378273014456245169422336/5817292837500093432997181104355984276223496430057669169901213027737741062055955724378619437814926883934224960780737255553232767489520389398507586046875.*x1.^5-94267425310773612599638740322629208595714990909621095965576142327181279246584265780378361930594498757706795149698078389699551522017848691472848705458783911936/92323669160480649500239151448965223788264790287476352875871084757435582733195826210180011933366120162971669141457400655216222482707293868859536783667265625.*x1.^4+33750253531325596345124977498815779434900844255428881286847640207252938674043829294981084784890319038148035145537994507247102141432693715258453281704155021312/106527310569785364807968251671882950524920911870165022549082020873964133922918261011746167615422446341890387470912385371403333633893031387145619365769921875.*x1.^3-121115835517746494394166199580632149437241601272999328914442173693156498884735106053392300700051676118679651553633528158918481769660983714572459994328070094848/2308091729012016237505978786224130594706619757186908821896777118935889568329895655254500298334153004074291728536435016380405562067682346721488419591681640625

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2