KEMBAR78
Curve Fitting Flowchart and Programs | PDF
0% found this document useful (0 votes)
330 views10 pages

Curve Fitting Flowchart and Programs

Uploaded by

Diya Shetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
330 views10 pages

Curve Fitting Flowchart and Programs

Uploaded by

Diya Shetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
<1 enor tne gon unborn ‘moans No Forl=4:n) Rid Enter the given valuas of x and Roadx a5 x | Beret a" | yas x) and y() respectively in proper sequence. y meat intially deine dx = Sp = 0, by = Sy = 0, éxy = S, = and &x” = Sy =0. Fori=2, S)=0+x(1)=x(1) Sp=x(1) + x(2) 81 =0+y(1)=y(1) S; =y(1) + y(2) + (1) y(t) = x(1) -y(1) S2= x(t) y(1)* x@)- 72) x(t) x(1)= A |S = BANE + Bay? ‘The process is continued for'’ numberof values. | veo fH /P Liisi |" int the table for given values of x and y as xy ex y As per least square criteria, adx+nb=dy = —» aSy+nb=S, adx'+bax=dxy > aS3+bSy=Sz Now according to Cramer's rule, So a pea-[er | =90"8e-" 5s tt means ba=a,=[e! gf 2S17S0-# =a,=|82 Sil =s)xs)-s,* ob=dy=[20 5H] =5)*5:-81*5y For values of a and b, 4, 4, ofa = a=Q and p= [ina ate [Print tne values of’ and] ats [FRISBY ne Pt to tal equation on y= ax +] ‘means a = Flowchart No. 8.1 : For straight line equation y = ax + b Program to fit a straight line by Least square criteria (y=ax+b) ‘n-input(Enter the number of inputs for i=! x()=input(Entor the values ofx =; }-y ‘y(i)=input(Enter the values of y = end S0=0; Si=0; 52=0; S30; forimim 80=S0+x(i) Find the values of Sy, S,, S, and S, for all given values of x and Ex. yas, Sy = Ex, S, = By, 5, Exy and Print the. table for values of x and y as fprinti(%f od wf Nn x( 1), yli).2e64) * 2,y6i)* XC); =e ¥ a ona i st e Pessoa ae50'50-°S3 Formulate the equations of straight line using least square das1°S0-0°S2; > Jeriteria and solve them by using Cramer's rule. Find values of ene ‘determinant of d, d, and dj. a=da/d; i bedb/d; fprintf(Ans:- a=%f =f", inten \ty =e Se [Output| Enter the number of inputs = 7 Enter the values of Enter the values of y = 0.5 x y a x” Enter the values of x Enter the values of y = 2.6 0.500000 1.000000 04600000 Enter the values of x = 9 .s00000 —4,000000 5.000000 Enter the values of y = 2 2.000000 9,000000 6.000000 Enter the valuos of x = 4 4.000000 16,000000 * 16.000000 Ratec:she yatonsiol ye 4) 3.500000 6.000000 17,6000 Raise tis VaR las 6.000000° 36,000009 3.000000 urate 500000 —49,000000 8.600000 Enter the values of x = 6 Enter the values of y = 6 Entor the valuos of x = 7 It enter given values of x and y a8} means | x(i) and y(i) respectively. Read x a5 x() Read y as y(i) Initially put Ex = Sy = 0, Ly = $, = 0, Exy=§, Bx? =85=0, x’y = 8, =0, Ex°=S, = Oand Ix! =S,=0. Fori=1 Sy =0+x(1)= x(1) 8) =0+y)=¥1) yt) +¥2) So 80 0 S22 0+x(1)-y(1) =H(1) (1) $2 =x(1)-¥(1) + #2)-¥2) $178,490) 2 S)=S)+x0*y0) y= 04x(1)-x(1) = BAD! S32 k(NF + oI =S,+x()*. ax # | So ene ie Irreans | Se=O+x(1)-x(1) y(t) = CHP“) = [x(1)F - y(1) * QF -v(2) S5= Sq +x{i)*() =x, 5 = 0 + x(1) -x(1) (1) = BC S_= (DI + QI 25, + x() + x0) +x) * x0 SiS SHES 8) =0#x(1)-x(1) x(t) x(t) = COI | Se= Exc + xe ‘This process is continued for ‘n’ number of values. Formulate the equations of parabolic curve using least square criteria and express them In.a matrix form as coefficient matrix peat | (l= a.nd constant matrix [8] = b. ‘Solve the above matrix by using MATLAB ‘command 'linsolve' or by using Gauss elimination method. —!t____ print the values of a, b and c. 1 means 7 __ etn tral qin aaatony =a? bx : For Quadratic equation y = ax’ + bx + ¢ Flowchart No. 8. ‘Binput(Enter the number of inputs =; for i=in x()=input(Entor tho values of x = 9); fori=tm From i= 1 (0 n, find the values of Sy, S,, Sy, Sy) Sy Sg and Sg a8 50=50+x1i); sige 8) = Exy 8, = Ly, 8, = E1y S2es2+x(*¥(); 7 8) = Ex, S,=Zs'y, S,= 22° i S9=S34x()*x(); i 4 S444 x)*x(* YE: and Se S5=85+x()"x()"x(; S6=S8-+x(i"x() "x(x; end see Formulate the equations of parabolic curve | Lea > | using least square criteria and express them in i | & matrix form as coefficient matrix [A] = a betst; and constant matrix [B] = b 82; 84 1 volinsolve(a.b): fprintf(Ans ene, v1). ¥(2). 010); yi > fiauradtey=nse24ntcese «rywarwtay, — Supe Enter the values of y Enter the number of inputs = 7 Enter the values of x Enter the values of x = -3 Enter the values of y Enter the values of x = 3 Enter the values of y = 12 Entec the values of y = 30 Enter the values of x = 2 a= 20 7 Enter the values of y = 4 o 2 0 ater the values of = +1 198 0 28 Enter the values of y = 1 n Enter the values of x = 0 Enter the values of y = 2 2.118048 b= 2.928571 c = 1.666687 2.119048 ~ 2-+2.828571%+ 1,686657>> It ‘ —lte [Enter the given number of mean EF inputs, sey 'n!. No Enter the values of x from I, | 11o'n’as, x= x() and store ‘means | values of y as temp. Make new ‘column for y(i) asy(!) = log (temp). athe [inti put Sp = 0, 8 =0, 8, = 0 and Sy =0] Fort=1, For = 2, Sy =0+x(1)= x(1) Sp = x(1) + x(2) Sy =0 + y(1)= (1) S, = y(t) + (2) Sp= 5p +x) 81 =; +00) S2=S2 +x) *¥O Sy= Sy +x(i) * xt) WL} Sp = 0 + x(1) -y(1) = x(1) (1) | Sp = x(1) - yl) + x02) - (2) means Sy=04x(1)-x1)= HCN? | Sy= ECHO The process is continued for 'n’ number of values. As per least square criteria, ayIx+nby=Zy 2 a,Sy#nby=S, ay Ix" + by Ex = Exy = 3483 +DySq = Sp Now according to Cramer's rule, Sp on = Sg * Sp—nxS, 5 So So So 3 G=8,7 8-975 4,=8;*Sp—n* Sp a 25150752 sy %,| | =S0*82- 5155 For values of a, and by, it, [ To find values of 'at and 'b’ use, Tears bee’, —t. ‘sau Treaty | Print the final equation of curve as y= ab'.] Flowchart No. 8.3 : For curve y = ab™ Program to fit a curve by Least square criteria (y=atb4x) ainputf\n Hater numberof slements ="; }-9! enter the given number of Inputs, say "1 Enter the given values of x from 1 to n as x(i) and | store values of y as 'temp'. Make new column for y(i) | 8 y(i) = log, (temp). 5 > Initially define Ex = 8, = 0, Zy = Ext=S,=0. From i= I tom, calculate the values of Sq Sy S, and S; as, S) = Ex 8, = Ly, S, = Lay ad Sy = 82=82+x(i)*¥10: S3=83+x(i)*x end d=S0*S0-n"S3: da=S1*S0-n"S2; b=50°S2.S1S3; > alsda/a; bi=db/d; Formulate the equations of of straight line using least squar criteria and solve them by using Cramer's rule. Find values of | determinant of d, da and db. em (a1); 4 a= exp (b1); i [Output . ‘Enter number of elements = § Enter the values of x = 2.1 Enter the values of y = 6.14 Enter the values of x = 2.5 Enter the values of y = 6.788 “Enter the values of x = 3.1 Enter the values of y = 10.29 Enter the values of x = 3.5 Enter the values of y = 19.58 Enter the vales of x = 4.1 Enter the values of y = 20,678 ye=(199869)(2.000778)*x>> It —— [Enter the given number of i 1 mean ff gi f inputs say 'n’] No. Enter the values of x from 1 to 'n’ as re | band values of y as ‘temp’. means | Now,-calculate, x(i) and y(i) as, x(i) = log (tx) and ¥({) = log (temp). 0 =o X ies a0. tye B] tent pu'8p20,5,=0,5)=00085)=6] =o —Fori=tin> : Fori= 1, Fori=2, Yes, Sp=0+x(1) =x(1) Sq = »(1} + x(2) Sy oF y= y(t) $1 = (1) +y(2) x) Sy= Sy+x() + xQ) 8y= 0+ x(1)-x(1)= (NF | Sy = CANT? + (QI? ‘The process is continued for 'n’ number of values. ‘As perleast square criteria, ay Sx +n, = Sy ay Ex? +b, Ex= Now according to Cramer's rule, a §| 8050-985 n al =8,*Sy-n* 8, B es0H5-91955 For values of ay and by, b= ay= 2 and b= % It [ To find values of ‘a! and ‘b' use, a=" and | Flowchart No. 8.4 : For curve y = ax” mM) Sp= 0+ (1) + y11) = x(1)- yt). | Sp x(1)- YC1) + x(2) - (2) Tears Program to fit a curve by Least square criteria (y=a"x*b) 4 nsinpottin Ener nurse of stbante = a. number. of faputs ay forietn ‘c-input(\n Ester the value of x = tomp=input(\n Enter the value of y =: xti)=IoaC2): y@)=logitemp): From i= 1 to m enter values of x as x, and values of ¥ a5 temp. Now caleulate x(i) and y(i) as, £ adi) = tog, (t,) and y(i) = log, (temp). end s0=0; S1=0; S2=0; 83-0; <5 Iniiany aetne Ex = 55 = 0, Ey =5, and EF =5,=0. x sisst+yi; > | From i= 1 to a, caleulate the values of Sy S,, S, and s2=satxi)y: | Sy as, Sy = Ex, 8 = Zy, 8, = Exy and Sy = Ex, 83=534x)%ti: end 4=s0'S0-0°53; da=S1*S0-0"S2; eb=S0°S2-S1°S3; Formulate the equations of straight line using > | least square criteria. and solve them by using ‘Cramer's rule, Find values of determinant of d, da and ab. Output] Enter number of elements = 5 Enter tho value of x = 05 Enter the value of y = 0.7425 Enter the value of x = 1.5 Enter the value of y = 9.8579 Enter the value of x = 2 Enter the value of y = 6.9397 Entor the value of x = 2.6 Entor tho value of y = 8.201, Enter the value of x = 3 Enter the value of y = 10.912 y=iasnocosaye* (.A00073)>> It_, [Enter the given number of inputs means | say'n’, From i= 1 ton, enter the value It_,_ | ofx as x(i). Store values of y means | as temp. Calculate y(i) = log, (temp). Intlatly put Sp * 0, Sy * 0, 8 * 0.and Sy =0. + 3 Forts, Forl=2, 8y=0+'x(1) = x(1) Sy = H(t} + 12) 8, =0 + y(t) =y(1) Sy = y(1) + y(2) Bp = 0+ x(1) > y(1) = x(1) CA) |] Sy= HCH) YH) # x2) 2) 8y= 04 x(t): x(t) = OC)? | Sy = fC? + aI The process is continued for‘! number of values. Treans ‘As per least square citer, ay Extnby= By — —e a,S9 + rby= Sy ay Bx? + by Ex= By —> 8183 * D180 = Se Now according to Cramer's rule, For values of a, and by, aye 4a and by= Sb ¢ ¢ 1 (ey values of a and b on) “Theané 1 and b= ay. ‘te | Print the final equation of curve as y= @ ) Flowchart No, 8.5 : For curve y= a0" Program to fit a curve by Least square criteria (y=a"e*(bx)) n=input(\n Enter number of elements =‘: fori=in ‘x(i)=input(\n Enter the value of x = ‘temp=input(\n Enter the value of y =") ‘yli)=lon(temp); end : = s2+x(i)* yi; S3=S3+x(i)*x(i); end db=S0*S2-S1°S3;, 3 al=da/d; bi=db/d;_ -exp(b1); } > fprintf(\n y=(%f)e~ (%f)x'a,b); Output | Enter number of elements = 4 Enter the value of x = 0.1 Enter the value of y = 1.832 Enter the value of x = 0.2 Enter the value of y = 2.238 Enter the value of x = 0.3 Enter the value of y = 2.7333 Enter the value of x = 0.4 Enter the value of y = 3.338 y4(1\600073)e ™(1.999818)x>> > | initiany define Bx = §, and Zx? = S,=0. }> [Enter the giv {and store values of y as temp make new columa for y(#) as y(l) = log, (temp). i From {= 1 to n, calculate the values of Sy S,,S, and S, as, Sp = Ex, 8, = Ly, S, = Exy and 8, = Ex, Formulate the equations of straight line using least / square criteria and solve them by using Cramer's rule. Find values of determinant of d, da and db.

You might also like