MATLAB Answers

Jake
0

How to plot a line where the variable changes condition.

Asked by Jake
on 25 Nov 2012
Accepted Answer by Matt J

So from 0<x<1.8 Z=1.25*((0.72*(x/5))-((x/5).^2));

and from 1.8<x<5 Z=(1125/1024)*((0.28+(0.72*(x/5)))-((x/5).^2));

Is there anyway I can enter this without putting it into 2 different parts?

Thanks

  0 Comments

Tags

Products

No products are associated with this question.

2 Answers

Answer by Matt J
on 25 Nov 2012
 Accepted answer

   Z=@(x) 1.25*((0.72*(x/5))-((x/5).^2)).*(x>0 & x<1.8)+...
           (1125/1024)*((0.28+(0.72*(x/5)))-((x/5).^2)).*(x>1.8 & x<5);

  0 Comments


Answer by bym
on 25 Nov 2012

c = [-.05 .18 0;...
     -.0439 .1582 .3076];
b = [0,1.8,5];
f = mkpp(b,c);
xx = 0:.1:5;
plot(xx,ppval(f,xx))

  0 Comments


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!