Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to plot continous function with different definations

1 次查看(过去 30 天)
Hello all, I want to plot variation of function P(x) over range of x from -10 till 20 where P(x) is defined as P(x)= 0 if x<=0; =x if 0<=x<=1; =2-x if 1<=x<=2; =0 for x>2;
for this I have written following code: clear; dx=0.5; x=-10:dx:20; function z = bilinear(x) if x>=2 z=0; elseif 2>x>=1 z=2-x; elseif 1>x>=0 z=x; else z=0; end fp=bilinear(x); plot(x,fp);
and matlab is giving me following error: ??? Error: File: Q2.m Line: 3 Column: 1 Function definitions are not permitted in this context.
Can somebody please help me to debug this,
Thanks in advance,
Nikhil

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by