matlab area under curve

来源:百度知道 编辑:UC知道 时间:2024/05/25 18:26:24
Consider the function y=5*e^[-(x-3)^2] 用matlab 问输入 xmin xmax. 然后画图 和求出area undercurve 需要写自己的公式
Your output should look like the following:
>> gaussian
Enter a value for xmin: -1
Enter a value for xmax: 4
The area under the curve between x=-1.00 and x=4.00 is 8.16
>>

将下列语句保存在一个文件名为gaussian.m的Matlab脚本文件里:
clc;clear;
syms x y
y=5*exp(-(x-3)^2);
xmin=input('Enter a value for xmin: ');
xmax=input('Enter a value for xmin: ');
S=eval(int(y,x,xmin,xmax));
str=sprintf('The area under the curve between x=%.2f and x=%.2f is %.2f',xmin,xmax,S);
disp(str);

function gaussian()
%%不知道你要用什么积分来计算
x0=input('Enter a value for xmin:');
x1=input('Enter a value for xmax:');

%%Matlab自带的符号积分来计算
syms x
area=double(int(5*exp(-(x-3)^2),x,x0,x1));

disp(['The area under the curve between x= ', num2str(x0), ' and x= ' , num2str(x1) ,' is ',num2str(area)]);