How to plot a function which is defined on different subintervals
5 次查看(过去 30 天)
显示 更早的评论
I am trying to plot the function
, ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/541936/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/541931/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/541936/image.png)
But I don't know how to write the code for the definition of the function f which is given on different subintervals.
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!