How can I subtract this matrix in this function?

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 件のコメント

Stephen23
Stephen23 2016 年 3 月 19 日
What is T ? What values are you calling Verhulst_KT with ?
Jan
Jan 2016 年 3 月 19 日
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;

サインインしてコメントする。

 採用された回答

John BG
John BG 2016 年 3 月 20 日

1 投票

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 件のコメント

Tyler Clarke
Tyler Clarke 2016 年 3 月 20 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

質問済み:

2016 年 3 月 19 日

コメント済み:

2016 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by