QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1623|回复: 2
打印 上一主题 下一主题

函数绘图---例题

[复制链接]
字体大小: 正常 放大
回帖奖励 1 点体力 回复本帖可获得 1 点体力奖励! 每人限 1 次

413

主题

36

听众

1854

积分

升级  85.4%

  • TA的每日心情
    开心
    2019-9-18 21:55
  • 签到天数: 258 天

    [LV.8]以坛为家I

    社区QQ达人

    群组2015国赛冲刺

    群组2016美赛公益课程

    群组国赛讨论

    群组第三届数模基础实训

    群组Matlab讨论组

    跳转到指定楼层
    1#
    发表于 2015-9-18 21:13 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    创建一个函数的函数,它能够画出所有只有一个自变量的MATLAB函数的图象,自变量的范围是用户指定的始值和终值。
    答案:
    这个函数有两个输入参数,第一个是要画的函数的函数名,第二个是两元素向量,它指明了画图的取值范围。
    1.陈述问题
    创建一个函数的函数,它能够画出所有只有一个自变量的MATLAB函数的图象,自变量的范围由用户指定。
    2.定义输入输出函数的输入有两个
    (1)包含有函数名的字符串
    (2)包含有起始值和终值的2元素向量函数的输出是所要画的图象
    3.设计算法这个函数可以分为4大步:
    Check for a legal number of arguments
    Check that the second argument has two elements
    Calculate the value of the function between the start and stoppoints
    Plot and label the function
    第三四大步的伪代码如下
    n_steps ← 100
    step_size ← (xlim(2) – xlim(1)) / nsteps
    x ← xlim(1):step_size:xlim(2)
    y ← feval(fun, x)
    plot(x, y)
    title(['bf Plot of function ' fun ' (x)'])
    xlabel('\bfx;)
    ylabel(['bf ' fun ' (x)'])



    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
    数学中国版主团队!

    413

    主题

    36

    听众

    1854

    积分

    升级  85.4%

  • TA的每日心情
    开心
    2019-9-18 21:55
  • 签到天数: 258 天

    [LV.8]以坛为家I

    社区QQ达人

    群组2015国赛冲刺

    群组2016美赛公益课程

    群组国赛讨论

    群组第三届数模基础实训

    群组Matlab讨论组

    1. function quickplot(fun,xlim)
    2. %QUICKPLOT Generate quick plot of a function
    3. % Function QUICKPLOT generates a quick plot
    4. % of a function contained in a external mfile,
    5. % between user-specified x limits.
    6. % Define variables:
    7. % fun                   --Function to plot
    8. % msg                   --Error message
    9. % n_steps               --Number of steps to plot
    10. % step_size             --Step size
    11. % x                     --X-values to plot
    12. % y                     --Y-values to plot
    13. % xlim                  --Plot x limits
    14. % Record of revisions:
    15. % Date Programmer Description of change
    16. % ==== ========== =====================
    17. % 12/17/98 S. J. Chapman Original code
    18. % Check for a legal number of input arguments.
    19. msg = nargchk(2,2,nargin);
    20. error(msg);
    21. % Check the second argument to see if it has two
    22. % elements. Note that this double test allows the
    23. % argument to be either a row or a column vector.
    24. if ( size(xlim,1) == 1 & size(xlim,2) == 2 ) | ...
    25. ( size(xlim,1) == 2 & size(xlim,2) == 1 )
    26.     % Ok        --continue processing.
    27.     n_steps = 100;
    28.     step_size = (xlim(2) - xlim(1)) / n_steps;
    29.     x = xlim(1):step_size:xlim(2);
    30.     y = feval(fun,x);
    31.     plot(x,y);
    32.     title(['\bfPlot of function ' fun '(x)']);
    33.     xlabel('\bfx');
    34.     ylabel(['\bf' fun '(x)']);
    35. else
    36.     % Else wrong number of elements in xlim.
    37.     error('Incorrect number of elements in xlim.');
    38. end

    数学中国版主团队!
    回复

    使用道具 举报

    413

    主题

    36

    听众

    1854

    积分

    升级  85.4%

  • TA的每日心情
    开心
    2019-9-18 21:55
  • 签到天数: 258 天

    [LV.8]以坛为家I

    社区QQ达人

    群组2015国赛冲刺

    群组2016美赛公益课程

    群组国赛讨论

    群组第三届数模基础实训

    群组Matlab讨论组

    附件:详细内容。

    画图像的函数.doc

    63 KB, 下载次数: 0, 下载积分: 体力 -2 点

    详细内容

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2025-5-9 13:04 , Processed in 0.424791 second(s), 67 queries .

    回顶部