Reputation: 993
I am trying to plot a ramp function in MATLAB. I have the following function for my ramp:
function [ y ] = ramp(x)
y=zeros(size(x));
y(x>=0)=linspace(0,x(end),length(x(x>=0)))
end
But, I want it to have a similiar effect as my step function
syms x
ezplot(5*heaviside(x-1), [-10, 10])
When I use this code:
syms x
ezplot(5*ramp(x-1), [-10, 10])
When I do (x-1) it seems to throw an error that it is impossible, may I ask for some modificaitons?:
Cannot prove '0 <= x - 1' literally. To test the statement mathematically,
use isAlways.
Upvotes: 0
Views: 9337
Reputation:
Your step function plot works with a function of symbolic variable x. But ramp
, the way you have written it, is a function that expects numerical input (a vector of x-values). This is why your attempt to pass a symbolic x to it fails. Here is a correct way to plot this function:
x = linspace(-10,10,100);
plot(x, 5*ramp(x-1))
Alternatively, you can rewrite ramp
as a function of a symbolic variable:
function y = symbramp(x)
y = (x+abs(x))/2;
end
and plot it as you did with Heaviside:
syms x
ezplot(5*symbramp(x-1), [-10,10])
Upvotes: 1