远方Alan 2021-05-21 12:12 采纳率: 100%
浏览 61
已采纳

matlab数值积分进行运算

function SimpsonIt
a=input('input the left point a:');
b=input('input the right pointb:');
n=input('input the number of the equal disparting n:');
h=(b-a)/n;
x=a+h/2:h:b-h/2;
disp('input the function f(x):');
y=input('y=','s');
t=eval(y);
s=4*sum(t);
x=a:h:b;
t=eval(y);
s=s+2*sum(t)-t(1)-t(n+1);
s=h*s/6;
fprintf(1,'the result is:%4.4f',s);

这是辛普森算法的代码段,我用这个方法想要计算这个函数:

但是运行的输出结果是这个:

请教。

  • 写回答

1条回答 默认 最新

  • CSDN专家-Matlab_Fans 2021-05-21 19:17
    关注

    最后一行改为./,向量元素之间的乘除运算,需要用加点的乘除。y=x.^4./(exp(x)-1)

    input the left point a:1e-8
    input the right pointb:0.34
    input the number of the equal disparting n:1000
    input the function f(x):
    y=x.^4./(exp(x)-1)
    the result is:0.0029
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。