How can I subtract this matrix in this function?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tyler Clarke
el 19 de Mzo. de 2016
Comentada: Tyler Clarke
el 20 de Mzo. de 2016
Hello, I'm having some difficulty with implementing a matrix into a particular function I'm using in the code below:
% function dy = Verhulst_KT(t,y)
dy = zeros(1,1);
dy(1) = r*y(:)*(1-y(1)/(300 + 100*sin(pi/6*t-pi/2))-H );
end
Where H is defined by:
for i = 1:61
s = ones(1,60);
s(i) = rem(T(i),mod);
if s(i) < 10 && s(i) > 3
H(i) = 160;
else
H(i) = 0;
end
end
I've tried referring to individual positions in H within the function and to the whole matrix itself but either a single element is read which is not what I'm after or I get the error "In an assignment A(:) = B, the number of elements in A and B must be the same." I was just hoping I could get some quick assistance in what is hopefully a fairly simple problem. Thank you in advance.
EDIT: I'm using ode45 to solve the equation itself, T is a row matrix from 0:60 and r is a constant. In hindsight, I probably could've done with pasting in the whole code but I wanted to avoid unnecessary content, apologies for any confusion caused.
2 comentarios
Jan
el 19 de Mzo. de 2016
A simpler method to obtain H:
S = rem(T, m); % Do not use "mod" as a name of a variable
H = and(S > 3, S < 10) * 160;
Respuesta aceptada
John BG
el 20 de Mzo. de 2016
Tyler
1.- in order to have your V_KT function working, to prevent the error A(I)=B you mention and others i had to change it to the following:
function dy = V_KT(t,y) % your Verhulst_KT()
dy = zeros(1,1);
r=ones(1,length(y))
% H noise whatever not deflined
% dy(1) = r*y(:)*(1-y(1)./(300 + 100*sin(pi/6*t-pi/2))-H );
dy = r*y(:)*(1-y(1)./(300 + 100*sin(pi/6*t-pi/2)));
end
2.- regarding H, what are you trying to do with it, embed data or noise in the phase?
H has to have same size as t, your T otherwise when attempting to combine them inside the sin(pi/6 ..) MATLAB will say things referring to size mismatch.
3.-
you need to pass H in the function dy=V_KT(t,y,H)
otherwise how is dy going to have anything to do with H?
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!