24小时热门版块排行榜    

查看: 2116  |  回复: 6
【悬赏金币】回答本帖问题,作者小虫飞更高将赠送您 5 个金币

小虫飞更高

新虫 (初入文坛)

[求助] matlab光强编程,提示矩阵维度 必须一致,不知是哪里出现的问题,代码在下面 已有1人参与

代码如下:
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;
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hzlhm

至尊木虫 (著名写手)

【答案】应助回帖

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

» 本帖已获得的红花(最新10朵)

QQ:2120156492
2楼2020-09-08 19:50:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

小虫飞更高

新虫 (初入文坛)

送红花一朵
引用回帖:
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);
>>
3楼2020-09-11 11:15:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

小虫飞更高

新虫 (初入文坛)

引用回帖:
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
4楼2020-09-11 15:30:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

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是函数,应该不存在定义变量的问题。可能是软件的问题,重启试一试看。

» 本帖已获得的红花(最新10朵)

QQ:2120156492
5楼2020-09-11 22:54:25
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

小虫飞更高

新虫 (初入文坛)

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

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

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : lens.m
  • 2020-09-13 12:38:12, 569 bytes
6楼2020-09-13 12:38:15
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

小虫飞更高

新虫 (初入文坛)

引用回帖:
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);
7楼2020-09-13 20:38:56
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 小虫飞更高 的主题更新
不应助 确定回帖应助 (注意:应助才可能被奖励,但不允许灌水,必须填写15个字符以上)
信息提示
请填处理意见