How to represent function which is defined on different interval?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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 件のコメント
Jinman Park
2018 年 5 月 27 日
編集済み: Jinman Park
2018 年 5 月 27 日
Wow!! I've never seen code like this before!!
Thanks for your comment
Jinman Park
2018 年 5 月 28 日
編集済み: Jinman Park
2018 年 5 月 28 日
Can I ask you another question?
I wrote code
j=1;
g=@(x) 0;
phi_part_i=@(x,i) N*(x-(i-1)/N)*( ((i-1)/N <x) & (x<i/N) ) + N*((i+1)/N-x)*((i/N <x) & (x<(i+1)/N));
while(j<=(N-1))
g=@(x) g(x)+u(j,1)*phi_part_i(x,j);
j=j+1;
end
fplot(@(x) g(x),@(x) sin(pi*x),[0,1])
But, I got error
> In matlab.graphics.function.ParameterizedFunctionLine>getFunction
In matlab.graphics.function.ParameterizedFunctionLine/set.XFunction
In matlab.graphics.function.ParameterizedFunctionLine
In fplot>singleFplot (line 243)
In fplot>@(f1,f2)singleFplot(cax,{f1,f2},limits,extraOpts,args) (line 201)
In fplot>vectorizeFplot (line 201)
In fplot (line 163)
In week6_1_3 (line 27)
Can you give me an advice?
phi_part_i = @(x,i) N*(x-(i-1)/N).*( ((i-1)/N <x) & (x<i/N) ) + N*((i+1)/N-x).*((i/N <x) & (x<(i+1)/N));
Thanks.
Additionally, I found another mistake that I made.
I modified last part of my code to
fplot(g(x),@(x) sin(pi*x),[0,1])
Well, I'm really sorry to ask you another one.
I wrote similar code and I followed your advice.
j=1;
g=@(x) 0;
phi_odd_i=@(x,i)-4*(N^2)*((x-((i-1)/(2*N)))*(x-((i+1)/(2*N)))).*( ((i-1)/(2*N) <x) & (x<=(i+1)/(2*N)) );
phi_even_i=@(x,i) 2*(N^2)*((x-((i-2)/(2*N)))*(x-((i-1)/(2*N)))).*( ((i-2)/(2*N) <x) & (x<=i/(2*N)) ) + 2*(N^2)*((x-((i+2)/(2*N)))*(x-((i+1)/(2*N)))).*((i/(2*N) <x) & (x<=(i+2)/(2*N)));
while(j<=(2*N-1))
if(mod(j,2)==0)
g=@(x) g(x)+u(j,1)*phi_even_i(x,j);
else
g=@(x) g(x)+u(j,1)*phi_odd_i(x,j);
end
j=j+1;
end
fplot(g,[0,1],'b')
hold on
fplot(@(x) sin(pi*x),[0,1],'r')
hold off
end
But, I face the same error. Can you give me one more advice?
Notice how I change the * operators into .* operators in my response to you before. You need to do the same thing.
Thanks.
Your advice worked!!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Time Series Events についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
