Why does my graph come out wrong?

2 views (last 30 days)
Ara Omar
Ara Omar on 16 Jan 2022
Commented: Jaffar Ali Lone on 25 Jan 2022
I want to plot a simple function, ((x.^2)-1).^(2/3). But my plot comes out looking different from the mathematicly correct one. Why is that? To specify, the graph should not be able to go under the x=0 line, yet it does.
  2 Comments
Jaffar Ali Lone
Jaffar Ali Lone on 25 Jan 2022
@Jan Can you give me some hints/ideas about how to solve the following discrete time system in MATLAB;
Ex(k) = Ax(k) + Bu(k)
where E is Singular Matrix
If E = [1 0 0 0 0 0;0 1 0 0 0 0;0 0 1 0 0 0;0 0 0 1 0 0;0 0 0 0 0 0;0 0 0 0 0 0]; %6by6
A = [0 0 0 0 0.43478 0;0 -0.16666 0 0 0.000666 0;0 0 0 0 0 0.5;0 0 0 -0.14285 0 0.0005;22.9676 -21.9676 0 -1 0.0025 -0.0015;0 0 0 0 1 1]; %6by6
C = [22.9676 1 0 0 0.0025 0;0 22.9676 0 1 0 0.0015]; %2by6
B = [0;0;0;0;1;1]; %1by6
u = sin(t)
We can not use ode15s because the system is not continous

Sign in to comment.

Answers (2)

Jan
Jan on 16 Jan 2022
fplot(@(x) ((x.^2)-1).^(2/3))
  1 Comment
Ara Omar
Ara Omar on 16 Jan 2022
nevermind, i figured it out, i need an "abs" ahead of my function

Sign in to comment.


_
_ on 16 Jan 2022
x = -10:0.01:10;
y = (x.^2-1).^(2/3);
plot(x,y)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
Note the warning about complex values. The values of y where abs(x) < 1 are complex because x^2-1 < 0 where abs(x) < 1. To skip plotting this reagin, you can keep track of when y is real and only plot those elements:
idx = imag(y) == 0;
plot(x(idx),y(idx))
ylim([-5 25])
Note the lack of warning this time. You could also replace the complex y with NaNs and plot that:
y(~idx) = NaN;
plot(x,y)
ylim([-5 25])
  2 Comments
_
_ on 16 Jan 2022
If you want to plot abs(((x.^2)-1).^(2/3)), then that will work.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by