声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2511|回复: 2

[编程技巧] [转帖]MATLAB多项式两个不错的例子

[复制链接]
发表于 2006-4-15 13:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
来自:http://www.rit.edu/~pnveme/pigf/Polynomials/poly_index.html

例一:问题描述

1.GIF


定义:
2.gif
3.gif

For w = 60,000 N/m; L = 6 m; E = 200 GPa; I = 15E-06 kg - m2


  1. % in MATLAB
  2. % polynomial described as a vector of coefficients

  3. p = [0.000833 -0.01 0 0.18 0]

  4. % roots of the polynomial - points where ploynomial is zero
  5. % we know that it is zero at 0 and 6
  6. % (but it has 4 roots)
  7. r = roots(p) % roots are in r

  8. % we can obtain the original polynomial
  9. % by using the poly function
  10. p1 = poly(r)

  11. % returns a normalized polynomial
  12. % poly and roots are inverse functions

  13. % symbolic computation - expresses the polynomial
  14. % from the numerical format - note the rational
  15. % format for coefficients
  16. p2 = poly2sym(p)

  17. % expresses the polynomial numerically
  18. p3 = sym2poly(p2)

  19. % change the variable to s
  20. p4 = poly2sym(p3,'s')

  21. % in MATLAB
  22. % polynomial described as a vector of coefficients

  23. p = [0.000833 -0.01 0 0.18 0];

  24. % evaluate the polynomial between x = 0 and x = 6
  25. % and plot the resulting derflaction

  26. x = 0:0.1:6;
  27. y = polyval(p,x);

  28. % since usually the deflection is downwards we plot -y
  29. plot(x,-y,'r-')
  30. title('Uniformly Loaded Beam - deflection')
  31. xlabel('Length along beam - meter')
  32. ylabel('Deflection of beam - meter')
  33. text(1,0,'w=60,000, L = 6, E = 200e-09, I = 15 e-06')

  34. % Find maximum deflection by setting the
  35. % derivative of polynomial to zero
  36. q = polyder(p);
  37. xmax = roots(q);
  38. for i=1:length(xmax)
  39. if isreal(xmax(i)) & (xmax(i) > 0) & (xmax(i) < 6)
  40. ymax=polyval(p,xmax(i));
  41. fprintf('location of maximum deflection :'),disp(xmax(i))
  42. fprintf('value of maximum deflection :'),disp(ymax)
  43. end
  44. end
  45. 曲线拟合

  46. 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

  47. % in MATLAB
  48. % create sample data
  49. x = 0:0.1:3;
  50. y = sin(2*x);
  51. % lets fit curves 3,4,5 order
  52. plot(x,y,'ro','MarkerFaceColor','y')
  53. hold on
  54. str={'r--','b-','k:'};
  55. for i = 3:5
  56. ii = i -2;
  57. p = polyfit(x,y,i);
  58. yy=polyval(p,x);
  59. plot(x,yy,char(str(ii)));
  60. legend('Original data','degree 3','degree 4','degree 5')
  61. end
  62. hold off
  63. title('Polynomial Curve fit')
  64. xlabel('x')
  65. ylabel('y')
  66. grid
复制代码


4.jpg
回复
分享到:

使用道具 举报

 楼主| 发表于 2006-4-15 13:52 | 显示全部楼层

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

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

The transfer function based on the differential equation can be written in Matrix form as:
2.gif
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:
3.gif
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

4.gif

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 = [1 6.88 11.8];
    p2 = [-1.6 -14.8];
    p3 = [8.88 58.24 124];

    % 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 = [0 0 p22];
    det = p13 - p22
    % roots of the polynomial
    r = roots(det)
发表于 2006-4-16 20:44 | 显示全部楼层
第一个中的p = [0.000833 -0.01 0 0.18 0]应该是p = [0.000833 0 -0.01 0.18 0]吧?

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-14 09:51 , Processed in 0.071820 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表