필터 지우기
필터 지우기

How can I discretize a function so I can use it in a model?

조회 수: 15 (최근 30일)
Evelyn
Evelyn 2014년 3월 12일
편집: Chris C 2014년 3월 12일
I need to use discretized data in my model, but I have three continuous functions for three different time-periods. How can I implement this correctly?
  댓글 수: 2
Chris C
Chris C 2014년 3월 12일
Claire, that depends on a few things including: what the functions are, what the model is and what kind of precision you're looking for. If you could clarify a little bit I might be able to help.
Evelyn
Evelyn 2014년 3월 12일
편집: Evelyn 2014년 3월 12일
You have constants k and b. I need to make a vector [0, 1, ..., 720]
  • From 0:360-(1/2)k the function will be increasing from 0 to b
  • From 360-(1/2)k:360+(1/2)k the function will be b
  • From 360+(1/2)k:720 the function will be decreasing from b to 0
Thank you for looking at it!

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

채택된 답변

Chris C
Chris C 2014년 3월 12일
The great thing about your question is that you already have the continuous functions. The greater challenge is usually finding a function to represent your data, but since that isn't a problem this shouldn't be too tough. What I would do is create a time array and then solve your continuous functions at every time step within your time array. For example...
t = linspace(1,1000,100); %Generates a time vector from 1 to 1000 with 100 points
x = ones(length(t),3); % Initialize data matrix.
x(:,1) = cos(t); % Solve each equation at each node of the time vector
x(:,2) = 3*t.^2;
x(:,3) = log(t/5);
However, if your function changes rapidly in any zone your discretization should have more data, especially in that region. This might require you to use something like logspace of even to define your own discretization manually.
  댓글 수: 2
Evelyn
Evelyn 2014년 3월 12일
After some research, I think I understand that you get a matrix with three different columns for the different formulas, but is there any way you can just change after a specific time from formula so you get just one vector in the end?
Chris C
Chris C 2014년 3월 12일
편집: Chris C 2014년 3월 12일
This is not the most elegant approach, but it's probably the easiest to understand (at least for me) :)
k = 2;
b = 4;
t = linspace(0,720,721);
x = ones(length(t),1);
for i = 1:length(t)
if t(i)<360-k/2
x(i) = 'INSERT FUNCTION HERE';
elseif t(i) >= 360-k/2 && t(i)<360+k/2
x(i) = 'INSERT FUNCTION HERE';
else
x(i) = 'INSERT FUNCTION HERE';
end
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by