24 Mart 2010 Çarşamba

Matlab da if-else ve abs() Fonksiyonun Kullanımı

%www.ethemsulan.com
clear all
close all
x=-5:0.1:5
y=4-abs(x-2)
y1=y-4
subplot(4,1,1)
hold on
plot(x,y)
plot(x,y1,'r')
y2=abs(x-2)
subplot(4,1,2)
plot(x,y2)
y3=abs(x)
subplot(4,1,3)
plot(x,y3)
y4=abs(x)
subplot(4,1,4)
plot(x,y4)
%%%%%%%%%%%%%%%%%%%
%% ABS OLMAYAN
clear all
close all
x_1=-5:0.1:2
y_1=4-(-(x_1-2))
x_2=2:0.1:5
y_2=4-(x_2-2)
x=[x_1 x_2]
y=[y_1 y_2]
subplot(4,1,1)
hold on
subplot(4,1,1)
plot(x,y)
y1=y-4
hold on 
plot(x,y1,'r')
y2=y1
for indis=1:size(y1,2)
    if (y1(indis)<0) y2(indis)=-y1(indis)
   % else y2(indis)=y1(indis)
   %end 
    end
end
subplot(4,1,2)
plot(x,y2)
x1=x-2
subplot(4,1,3)
plot(x1,y2)
x4=-x1
y4=y2
subplot(4,1,4)
plot(x4,y4)

m5

Hiç yorum yok:

Yorum Gönder