aspen 发表于 2006-4-15 13:50

[转帖]MATLAB多项式两个不错的例子

来自: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 =

% 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 = ;

% 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

aspen 发表于 2006-4-15 13:52

回复:(aspen)[转帖]MATLAB多项式两个不错的例子

例二:质量、弹簧、减震系统


The transfer function based on the differential equation can be written in Matrix form as:

The left hand side refers to the Response variables while the right hand side is the Input variables

The above Matrix expression can be written succintly as:

Characteistic Equation:
The characteristic equation is wriiten as:

det A = 0

The roots of this equation indicates if the system is stable or unstable

Using appropriate values for the system parameters the characteristic matrix A can be obtained as



To find the roots of the characteristic equation we have to set the determinant of A to be zero.
The determinant is obtained by the operation (p1 * p3 - p2*p2)
Polynomial multiplication is termed as convolution

    % in MATLAB
    % create the three polynomials
    p1 = ;
    p2 = [-1.6 -14.8];
    p3 = ;

    % you can only add and subtract polynomials
    % of the same order

    p13 = conv(p1,p3);
    p22 = conv(p2,p2);

    % the degree of p13 is 2 more than p22
    % we introduce two leading coefficients of 0]

    p22 = ;
    det = p13 - p22
    % roots of the polynomial
    r = roots(det)

star198311 发表于 2006-4-16 20:44

第一个中的p = 应该是p = 吧?
页: [1]
查看完整版本: [转帖]MATLAB多项式两个不错的例子