作业帮 > 综合 > 作业

matlab报错,The integrand function must return an output vector

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/25 16:16:10
matlab报错,The integrand function must return an output vector of the same length ...序如下
syms f ;
la1=1310*10^-9;
c=3*10^8;
x=0; %光程差
f1=c/la1;
df=3.4*10^12; %谱宽
la2=1311*10^-9;
f2=c/la2;
t=sqrt(exp((-(f-f1)*(f-f1)-(f-f2)*(f-f2))/(2*df*df)))*cos(2*pi*x*f/c)/(sqrt(2*pi)*df);
y=quad(@(f) t,2.273076335877862*10^14,2.305329519450801*10^14)
报错:Error using quad (line 79)
The integrand function must return an output vector of the same length as the input vector.
matlab报错,The integrand function must return an output vector
la1=1310*10^-9;
c=3*10^8;
x=0; %光程差
f1=c/la1;
df=3.4*10^12; %谱宽
la2=1311*10^-9;
f2=c/la2;
t=@(f)abs(sqrt(exp((-(f-f1).*(f-f1)-(f-f2).*(f-f2))./(2.*df.*df))).*cos(2*pi*x*f/c)./(sqrt(2*pi)*df));
y=integral(t,2.273076335877862*10^14,2.305329519450801*10^14)
y =
0.3646
再问: 你的integral函数智能用在2012a和以上版本吧,我的2011b版本不支持这个函数貌似,还是报这个错:Undefined function 'integral' for input arguments of type 'function_handle'. 请问为什么函数要加个取绝对值的,中间为什么换成点乘
再答: 我的是2012b版本。加绝对值是为了把开平方运算的结果取单值。