当前位置: 首页 > 程序语言 >matlab光强编程,提示矩阵维度 必须一致,不知是哪里出现的问题,代码在下面

matlab光强编程,提示矩阵维度 必须一致,不知是哪里出现的问题,代码在下面

作者 小虫飞更高
来源: 小木虫 300 6 举报帖子
+关注

代码如下:
clear all;
k=10;
f=1004.8;
x=-1.5:0.01:1.5;
y=-1.5:0.01:1.5;
[x1,y1]=meshgrid(x,y);
r=sqrt(x1.^2+y1.^2);
Phi=atan(y1./x1);
I=(i*k*exp(i*(pi/2+k*f)).*sin(2.*Phi).*quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r.*sin(theta)),2.23,pi)).^2;
subplot(2,1,1);
mesh(x1,y1,I);
axis([-1.5 1.5 -1.5 1.5 0 1]);
subplot(2,1,2);
subimage(I*255);
axis off;

出现错误如下:
矩阵维度必须一致。

出错 formula>@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r.*sin(theta))

出错 quadl (line 62)
y = feval(f,x,varargin{:}); y = y(.';

出错 formula (line 9)
I=(i*k*exp(i*(pi/2+k*f)).*sin(2.*Phi).*quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r.*sin(theta)),2.23,pi)).^2; 返回小木虫查看更多

今日热帖
  • 精华评论
  • hzlhm

    问题出在,quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r.*sin(theta)),2.23,pi),这个数值积分命令上,该函数要求点对点,即已知值为单一数值(不接受数组数据)。所以你的问题,应用for循环语句来完成。
    matlab光强编程,提示矩阵维度 必须一致,不知是哪里出现的问题,代码在下面
    123.jpg

  • 小虫飞更高

    引用回帖:
    2楼: Originally posted by hzlhm at 2020-09-08 19:50:51
    问题出在,quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r.*sin(theta)),2.23,pi),这个数值积分命令上,该函数要求点对点,即已知值为单一数值(不接受数组数据)。所以你的问题,应用 ...

    你好,我按照你的编程输入了下,还是有提示错误,请你在帮我解答下,
    clear all;
    k=10;
    f=1004.8;
    x=-0.5:0.01:0.5;
    y=-0.5:0.01;0.5
    [x1,y1]=meshgrid(x,y);
    r=sqrt(x1.^2+y1.^2);
    [K,L]=size(r);
    for m=1:k
        for n=1:L
    Phi=atan(y1(n)./x1(m));
    r0=r(m,n);
    eq=quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r0.*sin(theta)),2.23,pi);
    I0=(i*k*exp(i*(pi/2+k*f))*sin(2*Phi)*eq).^2;
    I(m,n)=I0;
        end
    end
    Re=real(I);Im=imag(I);
    s.FaceColor='flat';
    %subplot(2,1,1);
    C=rand(K,L);
    mesh(x1,y1,real(I).C);hold on
    提示错误如下:
    formula

    ans =

        0.5000

    未定义与 'double' 类型的输入参数相对应的函数 'Besselk'。

    出错 formula>@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r0.*sin(theta))

    出错 quadl (line 62)
    y = feval(f,x,varargin{:}); y = y(.';

    出错 formula (line 13)
    eq=quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r0.*sin(theta)),2.23,pi);
    >>

  • 小虫飞更高

    引用回帖:
    2楼: Originally posted by hzlhm at 2020-09-08 19:50:51
    问题出在,quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*Besselk(2,k.*r.*sin(theta)),2.23,pi),这个数值积分命令上,该函数要求点对点,即已知值为单一数值(不接受数组数据)。所以你的问题,应用 ...

    刚我又调试了下,出现如下错误,您再帮我看下:
    k=10;
    f=1004.8;
    x=-0.5:0.01:0.5;
    y=-0.5:0.01:0.5;
    [x1,y1]=meshgrid(x,y);
    r=sqrt(x1.^2+y1.^2);
    [K,L]=size(r);
    for m=1:k
        for n=1:L
    Phi=atan(y1(n)./x1(m));
    r0=r(m,n);
    eq=quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*besselk(2,k.*r0.*sin(theta)),2.23,pi);
    I0=(i*k*exp(i*(pi/2+k*f))*sin(2*Phi)*eq)^2;
    I(m,n)=I0;
        end
    end
    Re=real(I);Im=imag(I);
    s.FaceColor='flat';
    %subplot(2,1,1);
    C=rand(K,L);
    mesh(x1,y1,real(I).C);hold on
    axis([-1.5 1.5 -1.5 1.5 0 1]);
    subplot(2,1,2);
    subimage(I*255);
    axis off
    提示错误:
    定义变量 "real" 或类 "real"。

    出错 para (line 22)
    mesh(x1,y1,real(I).C);hold on

  • hzlhm

    引用回帖:
    4楼: Originally posted by 小虫飞更高 at 2020-09-11 15:30:28
    刚我又调试了下,出现如下错误,您再帮我看下:
    k=10;
    f=1004.8;
    x=-0.5:0.01:0.5;
    y=-0.5:0.01:0.5;
    =meshgrid(x,y);
    r=sqrt(x1.^2+y1.^2);
    =size(r);
    for m=1:k
        for n=1:L
    Phi=atan(y1(n)./x1(m) ...

    real是函数,应该不存在定义变量的问题。可能是软件的问题,重启试一试看。

  • 小虫飞更高

    引用回帖:
    5楼: Originally posted by hzlhm at 2020-09-11 22:54:25
    real是函数,应该不存在定义变量的问题。可能是软件的问题,重启试一试看。...

    我试了试其他笔记本的电脑上的版本matlab,还是提示未定义变量‘real ’或类‘real’,请您运行下我的程序,看看是什么问题呢?

  • 小虫飞更高

    引用回帖:
    5楼: Originally posted by hzlhm at 2020-09-11 22:54:25
    real是函数,应该不存在定义变量的问题。可能是软件的问题,重启试一试看。...

    定义变量的问题解决了,但是又遇到了一个索引函数编制的问题,问题在代码后面:
    clear all;
    close all;
    clc;
    k=10;
    f=1004.8;
    x=-0.5:0.01:0.5;
    y=-0.5:0.01:0.5;
    [x1,y1]=meshgrid(x,y);%直角坐标转化为极坐标
    r=sqrt(x1.^2+y1.^2);
    [K,L]=size(r);
    for m=1:k
        for n=1:L
    Phi=atan(y1(n)./x1(m));
    r0=r(m,n);
    eq=quadl(@(theta)(1+cos(theta))./(1-cos(theta)).*sin(theta).*besselk(2,k.*r0.*sin(theta)),2.23,pi);
    I0=(i*k*exp(i*(pi/2+k*f))*sin(2.*Phi)*eq).^2;
    I(m,n)=I0;
        end
    end
    Re=real(I);
    Im=imag(I);
    s.FaceColor='flat';
    %subplot(2,1,1);
    C=rand(K,L);
    mesh(x1,y1,real(I).C);
    hold on ;
    axis([-1.5 1.5 -1.5 1.5 0 1]);
    subplot(2,1,2);
    subimage(I*255);
    axis off

    错误: 不能使用 {} 或 . 索引为函数编制索引。

    出错 para (line 25)
    mesh(x1,y1,real(I).C);

猜你喜欢
下载小木虫APP
与700万科研达人随时交流
  • 二维码
  • IOS
  • 安卓