필터 지우기
필터 지우기

try to keep track of the plot in a loop? how to do that?

조회 수: 2 (최근 30일)
William
William 2014년 3월 8일
댓글: William 2014년 3월 10일
%what I am doing here is to generate series of matrices, and multiply them together, but i want to keep track of the matrix elements, i might use the plot wrong, or how to do that? can anyone help me? I am a starter of coding, thank you!
function MonodromyM
double q
syms x
V(x)=(1/sqrt(2*pi))*(1/0.5)*exp((-x^2)/(2*0.5^2));
V2(x)=diff(x,2);
M=[1 0;0 1];
for i=1:1000
q=2*pi*rand(1);
A=[1 1;-V2(q) 1-V2(q)];
M=M*A;
hold on
fprintf('%d\n', M(1,1))
fprintf('%d\n', M(1,2))
fprintf('%d\n', M(2,1))
fprintf('%d\n', M(2,2))
end

채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 9일
William, a couple of things. See inlined comments:
function M = MonodromyM() % M is outputted by function and available for further
% ...analysis, for example in the MATLAB command window
syms x
V = (1/sqrt(2*pi))*(1/0.5)*exp((-x^2)/(2*0.5^2));
V2 = diff(V,2); % Did you mean to compute the 2nd deriv. of V?
M(:,:,1)=[1 0;0 1];
for i = 1:10
q = 2*pi*rand(1);
V2 = subs(V2,x,q); % substitute x by current value for q
A = [1 1;-V2 1-V2];
M(:,:,i+1) = M(:,:,i)*A; % save values of M in a 3D array
% hold on
% fprintf('%d\n', M(1,1))
% fprintf('%d\n', M(1,2))
% fprintf('%d\n', M(2,1))
% fprintf('%d\n', M(2,2))
end
  댓글 수: 1
William
William 2014년 3월 10일
V2 = subs(V2,x,q) after i remove the substitution part it works

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by