24小时热门版块排行榜    

查看: 2218  |  回复: 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的回帖

小虫飞更高

新虫 (初入文坛)

引用回帖:
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的回帖
查看全部 7 个回答

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的回帖

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的回帖
不应助 确定回帖应助 (注意:应助才可能被奖励,但不允许灌水,必须填写15个字符以上)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 306求调剂 +3 唐薏薏 2026-03-09 3/150 2026-03-10 22:30 by peike
[考研] 求调剂材料专硕293 +6 段_(:з」∠)_ 2026-03-10 6/300 2026-03-10 18:22 by ms629
[考研] 2026考研求调剂-材料类-本科211一志愿985-初试301分 +10 虫友233 2026-03-07 10/500 2026-03-10 17:10 by Demonsssss
[考研] 一志愿天津大学,英一数二305分求调剂,四六级已过 +7 小小番的茄 2026-03-09 7/350 2026-03-10 16:48 by ztnimte
[考研] 0703化学调剂 +3 三dd. 2026-03-10 3/150 2026-03-10 15:45 by peike
[考研] 复试调剂 +6 呼呼?~+123456 2026-03-08 8/400 2026-03-10 11:36 by 呼呼?~+123456
[考博] 2026博士申请 +6 起泡酒 2026-03-08 6/300 2026-03-10 10:26 by 何由彻
[考研] 294 英二数二物化 求调剂 +6 米饭团不好吃 2026-03-09 6/300 2026-03-09 23:55 by barlinike
[考研] 310 070300化学求调剂 +4 扑风铃的猫 2026-03-08 5/250 2026-03-09 19:46 by 30660438
[考研] 070300化学求调剂 +5 扑风铃的猫 2026-03-08 10/500 2026-03-09 13:58 by macy2011
[基金申请] 第二个面上项目的获批几率如何? +3 wawm9296 2026-03-04 5/250 2026-03-09 13:00 by xujie4132
[考研] 考研求调剂,工科,总分304 +4 矮子不想长高了 2026-03-08 7/350 2026-03-08 22:21 by 小木虫tim
[考博] 26年博士申请 +4 科研狗111 2026-03-07 4/200 2026-03-08 21:56 by 0611517sll
[考研] 0701-322 求调剂 +3 jiliuxian 2026-03-06 8/400 2026-03-08 19:31 by jiliuxian
[考研] 288求调剂085600材料与化工 +13 Daunrin 2026-03-07 15/750 2026-03-08 19:10 by 加号+
[考研] 070300化学求调剂292分 +3 打烊eee 2026-03-07 3/150 2026-03-07 20:04 by houyaoxu
[考研] 308求调剂 +7 倘若起风了呢 2026-03-05 9/450 2026-03-06 22:59 by 倘若起风了呢
[考研] 哈尔滨理工大学2026年研究生调剂,材料科学与化学工程学院研究生调剂 +3 xinliu866 2026-03-06 3/150 2026-03-06 19:42 by 祁东原神
[考研] 材料与化工354调剂 +4 Lucy-xiao 2026-03-06 7/350 2026-03-06 09:57 by hxuq8429
[考研] 301求调剂 +4 李LJR 2026-03-04 4/200 2026-03-05 13:31 by Iveryant
信息提示
请填处理意见