马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
来自:http://www.rit.edu/~pnveme/pigf/Polynomials/poly_index.html
例一:问题描述
定义:
For w = 60,000 N/m; L = 6 m; E = 200 GPa; I = 15E-06 kg - m2
- % in MATLAB
- % polynomial described as a vector of coefficients
- p = [0.000833 -0.01 0 0.18 0]
- % roots of the polynomial - points where ploynomial is zero
- % we know that it is zero at 0 and 6
- % (but it has 4 roots)
- r = roots(p) % roots are in r
- % we can obtain the original polynomial
- % by using the poly function
- p1 = poly(r)
- % returns a normalized polynomial
- % poly and roots are inverse functions
- % symbolic computation - expresses the polynomial
- % from the numerical format - note the rational
- % format for coefficients
- p2 = poly2sym(p)
- % expresses the polynomial numerically
- p3 = sym2poly(p2)
- % change the variable to s
- p4 = poly2sym(p3,'s')
- % in MATLAB
- % polynomial described as a vector of coefficients
- p = [0.000833 -0.01 0 0.18 0];
- % evaluate the polynomial between x = 0 and x = 6
- % and plot the resulting derflaction
- x = 0:0.1:6;
- y = polyval(p,x);
- % since usually the deflection is downwards we plot -y
- plot(x,-y,'r-')
- title('Uniformly Loaded Beam - deflection')
- xlabel('Length along beam - meter')
- ylabel('Deflection of beam - meter')
- text(1,0,'w=60,000, L = 6, E = 200e-09, I = 15 e-06')
- % Find maximum deflection by setting the
- % derivative of polynomial to zero
- q = polyder(p);
- xmax = roots(q);
- for i=1:length(xmax)
- if isreal(xmax(i)) & (xmax(i) > 0) & (xmax(i) < 6)
- ymax=polyval(p,xmax(i));
- fprintf('location of maximum deflection :'),disp(xmax(i))
- fprintf('value of maximum deflection :'),disp(ymax)
- end
- end
- 曲线拟合
- Polynomials are very popular in curve fitting and estimation. We will generate a set of x and y data and will fit the data with different polynomial of a chosen order and compare the approximation
- % in MATLAB
- % create sample data
- x = 0:0.1:3;
- y = sin(2*x);
- % lets fit curves 3,4,5 order
- plot(x,y,'ro','MarkerFaceColor','y')
- hold on
- str={'r--','b-','k:'};
- for i = 3:5
- ii = i -2;
- p = polyfit(x,y,i);
- yy=polyval(p,x);
- plot(x,yy,char(str(ii)));
- legend('Original data','degree 3','degree 4','degree 5')
- end
- hold off
- title('Polynomial Curve fit')
- xlabel('x')
- ylabel('y')
- grid
复制代码
|