-4
時間に対して角度をプロットしたい。ここでは、コード:ベクトルは同じ長さでなければならない
clear all
close all
params.t0 = 0; % start time of simulation
params.tend = 10; % end time
params.m=2^8; %number of steps in each Brownian path
params.deltat=params.tend/params.m; % time increment for each Brownian path
params.R=4; % integer number to obtain EM stepsize from Brownian path stepsize
params.dt = params.R*params.deltat; %0.01; % time increment for both EM and ode45
params.D=0.001; % diffusion constant
deltat= params.tend/params.m; % time increment for each Brownian path
params.D=0.1; %diffsuion
params.R=4;
params.dt = params.R*params.deltat;
theta0=pi*rand(1);
phi0=2*pi*rand(1);
P_initial=[theta0;phi0];
[theta,phi]=difusion_SDE(params);
plot([0:params.dt:params.tend],[theta0,theta],'--*')
hold on
plot([0:params.dt:params.tend],[phi0,phi],'--*')
と関数ファイル:私は、コードを実行すると
function [theta,phi]=difusion_SDE(params)
dW=sqrt(params.deltat)*randn(2,params.m);
theta0=pi*rand(1);
phi0=2*pi*rand(1);
P_initial=[ theta0; phi0];
L = params.m/ params.R;
pem=zeros(2,L);
Ang_rescale=zeros(2,L);
Ptemp=P_initial;
for j=1:L
Winc = sum(dW(:,[ params.R*(j-1)+1: params.R*j]),2);
theta=Ptemp(1);
phi=Ptemp(2);
A=[ params.D.*cot(theta);...
0];
B=[sqrt(params.D) 0 ;...
0 sqrt(params.D)./sin(theta) ];
Ptemp=Ptemp+ params.dt*A+B*Winc;
pem(1,j)=Ptemp(1);
pem(2,j)=Ptemp(2);
Ang_rescale(1,j)=mod(pem(1,j),pi);
Ang_rescale(2,j)=mod(pem(2,j),2*pi);
theta= Ang_rescale(1,j);
phi=Ang_rescale(2,j);
end
は、私はプロット ベクトルを使用して、このメッセージのエラー エラーが同じ長さにする必要がありました。 このエラーを解決する助けに感謝します
'plot'関数への入力のサイズはどれくらいですか? – GameOfThrows
エラーが発生した行を表示する必要があります – Dan
コードのデバッグに役立つ多数のツール/関数があります。 [デバッガ](http://se.mathworks.com/help/matlab/debugging-code.html)、[サイズ](http://se.mathworks.com/help/matlab/ref/size.html) 、[length](http://se.mathworks.com/help/matlab/ref/length.html)、[numel](http://se.mathworks.com/help/matlab/ref/numel.html) ...あなたの好きなものを選び、それに行きましょう。それは面白くない、私はそれを知っているが、これは厳しい現実がどのように働くかである。将来的にMatlabで多くの作業をする場合は、デバッガの学習を強くお勧めします。 – patrik