How can I subtract this matrix in this function?

4 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 19 Mar 2016
What is T ? What values are you calling Verhulst_KT with ?
Jan
Jan on 19 Mar 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;

Sign in to comment.

Accepted Answer

John BG
John BG on 20 Mar 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
  1 Comment
Tyler Clarke
Tyler Clarke on 20 Mar 2016
I added H as a variable for the function as suggested in part 3 and redefined H in an if statement within the function also therefore making it a variable rather than a matrix and it turned out perfect. Thanks for your assistance.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!