如果我要整合一个功能
y = - ((F + h) M ^ 3 (cosh(h * M)+ M * beta * sinh(h * M)))/(h * M * cosh( h * M)+( - 1 + h * M ^ 2 * beta)* sinh(h * M)) - (alpha *(M ^ 2 *(F + h)*( - 1 + 2 * h ^ 2 * M ^ 2 + cosh(2 * h * M)-2 * h * M * sinh(2 * h * M)))/(8 *(h * M * cosh(h * M)+( - 1 + h) * M ^ 2 *测试版)*的sinh(H * M))^ 2));
关于x,其中
phi = 0.6;
x = 0.5;
M = 2;
theta = -1:0.5:1.5;
F = theta - 1;
h = 1 + phi*cos(2*pi*x);
alpha = 0.2;beta = 0.0;
我写了一个Mfile
function r = parameterIntegrate(F,h,M,beta,alpha,theta,phi)
% defining a nested function that uses one variable
phi = 0.6;
x = 0.5;
r = quad(@testf,0,1 + phi*cos(2*pi*x));
% simpson's rule from 0 to h
function y = testf(x)
h = 1 + phi*cos(2*pi*x);
theta = -1:0.5:1.5;
F = theta - 1;
M = 2;
beta = 0;
alpha = 0;
y = -((F+h)*M^3*(cosh(h*M)+M*beta*sinh(h*M)))/(h*M*cosh(h*M)+(-1+h*M^2*beta)*sinh(h*M))- (alpha*(M^2*(F+h)*(-1+2*h^2*M^2+ cosh(2*h*M)-2*h*M*sinh(2*h*M)))/(8*(h*M*cosh(h*M)+(-1+h*M^2*beta)*sinh(h*M))^2));
end
end
并通过
调用该函数tol = [1e-5 1e-3];
q = quad(@parameterIntegrate, 0, h,tol)
or
q = quad(@parameterIntegrate, 0,1 + phi*cos(2*pi*0.5),tol)
它的工作没有给我
Error using ==> plus
Matrix dimensions must agree.
答案 0 :(得分:0)
您的错误消息的含义是,对于某些代码行,有2个矩阵,但维度不匹配,因此无法添加它们。我建议你解决这个问题的方法如下:
.*
,./
和.^
。我怀疑如果你用步骤3改变乘法/除法,你的问题就会消失。