24小时热门版块排行榜    

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

小虫飞更高

新虫 (初入文坛)

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

小虫飞更高

新虫 (初入文坛)

引用回帖:
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的回帖
不应助 确定回帖应助 (注意:应助才可能被奖励,但不允许灌水,必须填写15个字符以上)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿211,0860总分286食品工程专业求调剂 +8 林林Winnie 2026-03-05 8/400 2026-03-10 18:44 by 清风月
[考研] 一志愿天津大学材料与化工275求调剂 10+4 穿只靴子 2026-03-07 18/900 2026-03-10 18:44 by chixmc
[考研] 欢迎211本科同学,过A区国家线,A区非偏远一本,交叉学科课题组 +23 lisimayy 2026-03-04 37/1850 2026-03-10 18:10 by a1763909
[考研] 收调剂 +7 调剂的考研学生 2026-03-10 7/350 2026-03-10 17:57 by 麦茶汤圆
[考研] 一志愿湖师大化学289求调剂 +5 XMCMM3.14159 2026-03-10 5/250 2026-03-10 15:41 by shangxh
[考研] 337一志愿华南理工材料求调剂 +5 mysdl 2026-03-07 5/250 2026-03-10 14:54 by ruiyingmiao
[考研] 材料与化工求调剂 +11 与冬清宁 2026-03-07 14/700 2026-03-10 14:23 by Linda Hu
[考研] 0703求调剂 +10 c297914 2026-03-06 11/550 2026-03-09 18:37 by 30660438
[考研] 337求调剂 +3 睡醒,。 2026-03-09 3/150 2026-03-09 10:02 by 求调剂zz
[考博] 26年博士申请 +4 科研狗111 2026-03-07 4/200 2026-03-08 21:56 by 0611517sll
[考研] 招调剂 +20 帆船哥 2026-03-04 23/1150 2026-03-08 16:25 by taycat
[考研] 322分 085600求调剂,有互联网+国金及主持省级大创经历 +4 熊境喆 2026-03-05 4/200 2026-03-07 22:04 by 星空星月
[考研] 材料专硕323求调剂 +5 李白26 2026-03-07 5/250 2026-03-07 16:46 by njzyff
[考研] 不限学校专业的调剂同学看过来 +5 啊摆啊摆 2026-03-05 9/450 2026-03-06 12:06 by 啊摆啊摆
[考研] 复试调剂 +5 呼呼?~+123456 2026-03-05 5/250 2026-03-05 19:43 by caszguilin
[考研] 求调剂 +3 泡了个椒 2026-03-04 4/200 2026-03-05 14:37 by 泡了个椒
[考研] 301求调剂 +4 李LJR 2026-03-04 4/200 2026-03-05 13:31 by Iveryant
[考研] 274环境工程求调剂 +6 扶柳盈江 2026-03-05 6/300 2026-03-05 13:16 by 梦天888
[考研] 307求调剂 +4 xuyuan111 2026-03-04 5/250 2026-03-04 20:39 by kakakapanpan
[考研] 0703化学求调剂 +3 将未有期 2026-03-04 3/150 2026-03-04 16:19 by sslc1985
信息提示
请填处理意见