how to plot y=|x| function without using abs,
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi im trying to plot two functions the first y=|x| the second y=|x+4|-|x^2-7| without abs func but with for and if please help thanks
1 commentaire
James Tursa
le 3 Déc 2016
What have you done so far? What specific problems are you having with your code?
Réponses (1)
bio lim
le 3 Déc 2016
Well you have to find the regions where your values of y are positive and negative. Here is an example of y = |x|.
x = -100:100;
for i = 1:length(x)
if x(i)<0
y(i) = -x(i);
else y(i) = x(i);
end
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175797/image.jpeg)
4 commentaires
bio lim
le 3 Déc 2016
x = -10:0.01:10;
% let's call a = |x+4|
% b = |x^2 - 7|
for i = 1:length(x)
if (x(i)+4<0)
a(i) = -(x(i)+4);
else a(i) = x(i)+4;
end
end
for i = 1:length(x)
if (x(i)^2-7<0)
b(i) = -(x(i)^2 -7);
else b(i) = x(i)^2 -7;
end
end
y = a - b;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/186333/image.jpeg)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!