Comparing two sequences of number but not symmetry

5 views (last 30 days)
Hi, I'm not sure under what section to ask.
But it is like asking general math formulation. I currently create a function to assingn a sequence of number into increasing order and decreasing order.
For example when I consider N=10, for decreasing, I set the Peak to 1, and for increasing, I set the peak to N=10. However when i compare both sequence, it does not give symmetry pattern.
Hoping someone can give me a hint if the formulation for Dmaxp1(2,k) need to be changed?
Thank you in advance.
solution:
10 10 10 10 9 9 8 8 7 7 %This is when peak =1
6 7 7 7 8 8 9 9 10 10 %This is when peak=N=10;
code;
function[AllVal]=GenPer(N)
Trend=0.05;
MaxD=10;
MinD=0;
Peak=10;
AllVal=zeros(3,N); %Output save in here
day=AllVal(1,:);
DmaxP1=AllVal(2,:);
DminP1=AllVal(3,:);
PeakD1=1:1:Peak; %number before peak day
PeakD2=Peak+1:1:N; %Number after peak day
for k=PeakD1
day(1,k)=k;
DmaxP1(2,k)=ceil(MaxD*(1-Trend)^(Peak-(k-1)));
DminP1(3,k)=MinD;
%Output
AllVal(1,k)=day(1,k);
AllVal(2,k)=DmaxP1(2,k);
AllVal(3,k)=DminP1(3,k);
end
for k=PeakD2
day(1,k)=k;
DmaxP1(2,k)=ceil(MaxD*(1-Trend)^((k-1)-Peak));
DminP1(3,k)=MinD;
%Output
AllVal(1,k)=day(1,k);
AllVal(2,k)=DmaxP1(2,k);
AllVal(3,k)=DminP1(3,k);
end
end
  1 Comment
Image Analyst
Image Analyst on 24 Jul 2019
I'm not sure what you're asking. Maybe have someone help you re-word it to explain better. Do you want to find the peak or max? Do you have the Signal Processing Toolbox so you can use its findpeaks() function?

Sign in to comment.

Answers (1)

Athul Prakash
Athul Prakash on 5 Aug 2019
Hey Hafizah,
Couldn't understand what you're trying to model here, so I can't comment on a different formula for DmaxP1(2, k).
However, I understand that you're confused by non-symmetric values you got for Peak=10 and Peak=1.
You can solve this issue by changing your indices in the formula as follows:
% Replace this line in the first for loop.
DmaxP1(2,k)=ceil(MaxD*(1-Trend)^(Peak-(k-1))); % your current code.
DmaxP1(2,k)=ceil(MaxD*(1-Trend)^(Peak-(k))); % replacement code to fix the issue.
% make a similar replacement in the second for loop also; change (k-1) to k
The code is assuming 0-indexed vector, but matlab is 1-indexed. Hence, you are producing peaks at index=Peak+1.
The above change fixes the issue.

Community Treasure Hunt

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

Start Hunting!