wjzxjh123520 发表于 2012-5-23 21:34

随机共振仿真出现问题,急!!!

主程序

%双极性随机二进制的随机共振仿真
clc;
clear all;
close all;
%信源
fs=5;
Ts=1/fs;
A=0.3;
h=1/fs;
a=1;
b=1;
D=0.045;
a=randint(1,60,2);
t=Ts:Ts:29999*Ts;
m=(a(ceil(t/100))-0.5)*2*A;

plot(t,m);
ylim([-0.5,0.5])
title('信源');

x1=m+sqrt(2*D)*randn(size(t));
x=srrr(a,b,h,x1);

figure(2)
plot(t,x)

子程序

%子程序:解四阶龙格库塔法
function x=srrr(a,b,h,xx)
x=zeros(1,length(xx));

for i=1:length(xx)-2
    k1=h*(a*x(i)-b*x(i).^3+xx(i));
    k2=h*(a*(x(i)+k1/2)-b*(x(i)+k1/2).^3+xx(i+1));
    k3=h*(a*(x(i)+k2/2)-b*(x(i)+k2/2).^3+xx(i+1));
    k4=h*(a*(x(i)+k3)-b*(x(i)+k3).^3+xx(i+2));   
    x(i+1)=x(i)+(k1+2*k2+2*k3+k4)/6;
end

以下是错误
??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> srrr at 7
    k2=h*(a*(x(i)+k1/2)-b*(x(i)+k1/2).^3+xx(i+1));

Error in ==> erjinzhicanshuduisuijigongzhengyingxiang at 21
x=srrr(a,b,h,x1);

??? Input argument "xx" is undefined.

Error in ==> srrr at 3
x=zeros(1,length(xx));

非常感谢大家。

wjzxjh123520 发表于 2012-5-23 21:57

回复 1 # wjzxjh123520 的帖子

与数组a重名了,把a=1,改成c=1,x=srrr(a,b,h,x1)改成x=srrr(c,b,h,x1)即可。

页: [1]
查看完整版本: 随机共振仿真出现问题,急!!!