|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
主程序
%双极性随机二进制的随机共振仿真
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));
非常感谢大家。 |
|