필터 지우기
필터 지우기

How to plot a function which is defined on different subintervals

조회 수: 5 (최근 30일)
I am trying to plot the function ,
But I don't know how to write the code for the definition of the function f which is given on different subintervals.
  댓글 수: 4

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 7일
There are several methods available. The most straight forward is to write a function that loops over the inputs, testing each one to decide what the result should be.
function y = f(X)
y = zeros(size(X));
for K = 1 : numel(X)
x = X(K);
if x < 2
y(K) = 0;
elseif x <= 5
y(K) = x.^2;
elseif x <= 8
y(K) = x-x.^3;
else
y(K) = 0;
end
end
With regards to those intervals you need, think about floor(x+1/2)
  댓글 수: 11
Cris19
Cris19 2021년 3월 10일
Thank you. I wonder if there is an alternative solution. I am interested to find the asymptotic behavior at +infinity of the solution of that ODE. So is this why I think it is interesting to see the plotting of the solution on intervals larger and larger, such as [0,10], [0,500] etc.
I really don't know how to code this...
Walter Roberson
Walter Roberson 2021년 3월 10일
At asymptopic behaviour is
syms n f(x)
D = symsum(dirac(x-n), n, 1, 200)
df = diff(f)
d2f = diff(df)
eqn = d2f + D*df + f == 0
dsolve([eqn, f(0)==0])
but in practice you will not get any solution. Even if you reduce it down to dirac at one particular integer you are not going to get a solution.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by