How to represent function which is defined on different interval?

11 ビュー (過去 30 日間)
Jinman Park
Jinman Park 2018 年 5 月 27 日
コメント済み: Jinman Park 2018 年 5 月 29 日
I'm trying to plot function that defined on different intervals like following.
Let
phi_i(x)=M*(x-(i-1)/M) on [(i-1)/M,i/M] and M*((i+1)/M-x) on [i/M,(i+1)/M] and 0 on other values.
I got values u_1, u_2 ...u_(M-1) and note u(x)=u_1 phi_1(x)+u_2 phi_2(x) +...+u_(M-1) phi(x)
How to plot u(x)?

採用された回答

Rik
Rik 2018 年 5 月 27 日
You can use a for-loop to compose the function out of the parts using anonymous functions:
phi_part_i=@(x,i) ...
M*(x-(i-1)/M)*( (i-1)/M <x & x< i/M ) + ...
M*((i+1)/M-x)*( i/M <x & x< (i+1)/M );
phi_1=@(x) phi_part_i(x,1);
phi_1_10=@(x) 0;
for m=1:10
phi_1_10=@(x) phi_1_10(x) + phi_part_i(x,m);
end
  7 件のコメント
Walter Roberson
Walter Roberson 2018 年 5 月 28 日
Notice how I change the * operators into .* operators in my response to you before. You need to do the same thing.
Jinman Park
Jinman Park 2018 年 5 月 29 日
Thanks.
Your advice worked!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by