Help plotting piecewise function?
古いコメントを表示
I'm new to matlab and was wondering if someone could help me plot the following function as I don't really know where to start....
x is an integer value between 1 to 10
V_{x}N= if x is even, [(3/x)*(3/(x-2))...*(3/4)]*2*N^x
if x is odd, [(5/x)*(5/(x-2))...(5/3)]*pi
N is arbitrary but a value of N=1 is passed into the function in order to plot it
2 件のコメント
Aye
2020 年 7 月 26 日
Mario Malic
2020 年 7 月 26 日
for x = 1 : 1 : 10
if mod(x,2) == 0
y(x) = [(3/x)*(3/(x-2))...*(3/4)]*2*N^x
else
y(x) = [(5/x)*(5/(x-2))...(5/3)]*pi
end
end
Vector y contains your functions from 1 to 10, then you'll have probably have to use for again to plot each on its interval if I understood correctly.
回答 (1 件)
KSSV
2020 年 7 月 26 日
YOu can proceed like this:
x = 1:10 ;
y = zeros(size(x)) ;
N = 1 ;
% x is even
idx = 2:2:length(x) ;
y(idx) = [(3./x(idx)).*(3./(x(idx)-2))*(3/4)]*2.*N.^x(idx) ;
% x is odd
idx = 1:2:length(x) ;
y(idx) = [(5./x(idx)).*(5./(x(idx)-2))*(5/3)]*pi ;
plot(x,y)
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!