Trying a overlapping but piecewise plot
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Here is my code:
clear all
close all
clc
syms a(x)
N1_0 = - (3*x^5)/16 + (5*x^3)/8 - (15*x)/16 + (1/2);
N2_0 = (3*x^5)/16 - (5*x^3)/8 + (15*x)/16 + 1/2;
N1_1 = - (3*x^5)/16 + x^4/16 + (5*x^3)/8 - (3*x^2)/8 - (7*x)/16 + 5/16;
N2_1 = - (3*x^5)/16 - x^4/16 + (5*x^3)/8 + (3*x^2)/8 - (7*x)/16 - 5/16;
N1_2 = - x^5/16 + x^4/16 + x^3/8 - x^2/8 - x/16 + 1/16;
N2_2 = x^5/16 + x^4/16 - x^3/8 - x^2/8 + x/16 + 1/16;
x1 = 0;
x2 = 0.25;
x3 = 0.5;
x4 = 0.75;
x5 = 1;
a(x) = piecewise(x1<=x<=x2,0,x4<=x<=x5,0,x3<=x<=x4,N1_0,x2<=x<=x3,N2_0,x2<=x<=x3,N1_1,x3<=x<=x4,N1_1,x2<=x<=x3,N2_0,x2<=x<=x3,N2_1,x3<=x<=x4,N2_2)
fplot(a)
The idea is to overlap N1_0 to N2_2 on to 0.5, without a residual solution, but the functions should overlap each other on the same plot/line
This is the pencil sketch of how it should look like:

Feel free to ask if you want to know anything about this
Using piecewise function was my idea (coz I thought it would work but it didn't) but it is not necessary.
Feel free to modify the code as you please
Using MATLAB online
Please help
Thanks
採用された回答
Star Strider
2022 年 10 月 31 日
The problem description leaves much to the imagination. If you want to offset them on the x-axis, this likely requires a loop. (I also made them functions in the event that the function argument was to be shifted, so for example the first would be ‘N1_0(x)’ the second ‘N1_0(x+0.5)’ and so for the others.) Here, I just shifted the fplot evaluation intervals.
syms a(x)
N1_0(x) = - (3*x^5)/16 + (5*x^3)/8 - (15*x)/16 + (1/2);
N2_0(x) = (3*x^5)/16 - (5*x^3)/8 + (15*x)/16 + 1/2;
N1_1(x) = - (3*x^5)/16 + x^4/16 + (5*x^3)/8 - (3*x^2)/8 - (7*x)/16 + 5/16;
N2_1(x) = - (3*x^5)/16 - x^4/16 + (5*x^3)/8 + (3*x^2)/8 - (7*x)/16 - 5/16;
N1_2(x) = - x^5/16 + x^4/16 + x^3/8 - x^2/8 - x/16 + 1/16;
N2_2(x) = x^5/16 + x^4/16 - x^3/8 - x^2/8 + x/16 + 1/16;
Nc = {N2_0; N1_1; N2_1; N1_2; N2_2};
x1 = 0;
x2 = 0.25;
x3 = 0.5;
x4 = 0.75;
x5 = 1;
% a(x) = piecewise(x1<=x<=x2,0,x4<=x<=x5,0,x3<=x<=x4,N1_0,x2<=x<=x3,N2_0,x2<=x<=x3,N1_1,x3<=x<=x4,N1_1,x2<=x<=x3,N2_0,x2<=x<=x3,N2_1,x3<=x<=x4,N2_2)
% fplot(a)
xv = [0 5];
figure
fplot(N1_0,xv)
hold on
for k = 1:numel(Nc)
fplot(Nc{k},[xv(1)+0.5*k xv(2)])
end
hold off
grid

The piecewise approach would work for discontinuous funcitons (so each defined over different, consecutive intervals of ‘x’), however that is not my impression of what you want to do.
.
8 件のコメント
Thanks for the help.
Your concept is cool but it doesn't achieve the "sketched" output I attached in the post.
Basically, each function that is orignially within the range [-1 1] is being compressed to 0.25 with a horizontal shift. The shape of the function in [-1 1] should remain the same but its length should now be 0.25 and each function has its own specified region. The final output is between x = 0 to x=1, just as I have shown in my sketch
Thanks again
Star Strider
2022 年 10 月 31 日
‘Your concept is cool but it doesn't achieve the "sketched" output I attached in the post.’
I don’t understand the ‘sketched output’ because it bears no resemblance to any of the actual functions.
‘Basically, each function that is orignially within the range [-1 1] is being compressed to 0.25 with a horizontal shift.’
This makes no sense to me.
.
Saim
2022 年 10 月 31 日
lets say the function N1_0, it is originally being considered only in the range x=-1 and x=+1. This shape should not change in the final output.
That is what I have shown in the sketch, if you look carefully makred as N(subscript1)(superscript0)
but what is different for the output is that with the same shape in mind (the height can change but not the shape it gives), it should compress to a range of x = 0 to x = 0.25 but shifted from x = 0.5 to 0.75 (as shown in sketch).
Something like this:

It took a few minutes for me to figure out the best way to do this.
Still using fplot, this appears to work —
syms a(x)
N1_0(x) = - (3*x^5)/16 + (5*x^3)/8 - (15*x)/16 + (1/2);
N2_0(x) = (3*x^5)/16 - (5*x^3)/8 + (15*x)/16 + 1/2;
N1_1(x) = - (3*x^5)/16 + x^4/16 + (5*x^3)/8 - (3*x^2)/8 - (7*x)/16 + 5/16;
N2_1(x) = - (3*x^5)/16 - x^4/16 + (5*x^3)/8 + (3*x^2)/8 - (7*x)/16 - 5/16;
N1_2(x) = - x^5/16 + x^4/16 + x^3/8 - x^2/8 - x/16 + 1/16;
N2_2(x) = x^5/16 + x^4/16 - x^3/8 - x^2/8 + x/16 + 1/16;
Nc = {N1_0; N2_0; N1_1; N2_1; N1_2; N2_2};
x1 = 0;
x2 = 0.25;
x3 = 0.5;
x4 = 0.75;
x5 = 1;
% a(x) = piecewise(x1<=x<=x2,0,x4<=x<=x5,0,x3<=x<=x4,N1_0,x2<=x<=x3,N2_0,x2<=x<=x3,N1_1,x3<=x<=x4,N1_1,x2<=x<=x3,N2_0,x2<=x<=x3,N2_1,x3<=x<=x4,N2_2)
% fplot(a)
lgdc = {'N_1^0','N_2^0','N_1^1','N_2^1','N_1^2','N_2^2'};
xv = [-1 1];
figure
hold on
for k = 1:numel(Nc)
hfp{k} = fplot(Nc{k},xv, 'DisplayName',lgdc{k});
end
hold off
grid
title('Original')
legend('Location','NE')

xv = [-1 1];
figure
hold on
for k = 1:numel(Nc)
hfp{k} = fplot(Nc{k},xv);
hfp{k}.Visible = 'off';
x = hfp{k}.XData;
y = hfp{k}.YData;
hp{k} = plot(x*0.125 + 0.125 + 0.5*k, y , 'DisplayName',lgdc{k});
end
hold off
grid
xlim([0 max(xlim)])
title('X-Scaled & X-Shifted')
legend([hp{:}],'Location','best')

I am not certain that I understood exactly the result you want, so make appropriate changes to get it.
The ‘x’ calculation is:
x*0.125 + 0.125 + 0.5*k
↑← SF ↑← CO ↑← VO
where ‘SF’ is the scaling factor to get the ‘x’ values to span 0.25, ‘CO’ is a constant offset, and ‘VO’ is the variable offset that increments with the loop. Change those as necessary to get the desired result.
.
Saim
2022 年 10 月 31 日
Thank you so much All I have to do is make some minor adjustments to match my first sketch but this is more than enough. Thanks a lot
Star Strider
2022 年 10 月 31 日
As always, my pleasure!
check this out, gives the exact first sketch output.
figure
hold on
for k = [1 4 6]
hfp{k} = fplot(Nc{k},xv);
hfp{k}.Visible = 'off';
x = hfp{k}.XData;
y = hfp{k}.YData;
hp{k} = plot(x*0.125 +.625, y , 'DisplayName',lgdc{k});
end
for k = [2 3 5]
hfp{k} = fplot(Nc{k},xv);
hfp{k}.Visible = 'off';
x = hfp{k}.XData;
y = hfp{k}.YData;
hp{k} = plot(x*0.125 +.375, y , 'DisplayName',lgdc{k});
end
hold off
grid
xlim([0 1])
title('X-Scaled & X-Shifted')
legend([hp{:}],'Location','best')
Still, all credit goes to you
PS I dont know how you run it here with the graphical and numerical output but still thanks a lot for all the help
As always, my pleasure!
Thank you!
I was curious, so I ran it to see what it looked like —
syms a(x)
N1_0(x) = - (3*x^5)/16 + (5*x^3)/8 - (15*x)/16 + (1/2);
N2_0(x) = (3*x^5)/16 - (5*x^3)/8 + (15*x)/16 + 1/2;
N1_1(x) = - (3*x^5)/16 + x^4/16 + (5*x^3)/8 - (3*x^2)/8 - (7*x)/16 + 5/16;
N2_1(x) = - (3*x^5)/16 - x^4/16 + (5*x^3)/8 + (3*x^2)/8 - (7*x)/16 - 5/16;
N1_2(x) = - x^5/16 + x^4/16 + x^3/8 - x^2/8 - x/16 + 1/16;
N2_2(x) = x^5/16 + x^4/16 - x^3/8 - x^2/8 + x/16 + 1/16;
Nc = {N1_0; N2_0; N1_1; N2_1; N1_2; N2_2};
x1 = 0;
x2 = 0.25;
x3 = 0.5;
x4 = 0.75;
x5 = 1;
lgdc = {'N_1^0','N_2^0','N_1^1','N_2^1','N_1^2','N_2^2'};
xv = [-1 1];
figure
hold on
for k = [1 4 6]
hfp{k} = fplot(Nc{k},xv);
hfp{k}.Visible = 'off';
x = hfp{k}.XData;
y = hfp{k}.YData;
hp{k} = plot(x*0.125 +.625, y , 'DisplayName',lgdc{k});
end
for k = [2 3 5]
hfp{k} = fplot(Nc{k},xv);
hfp{k}.Visible = 'off';
x = hfp{k}.XData;
y = hfp{k}.YData;
hp{k} = plot(x*0.125 +.375, y , 'DisplayName',lgdc{k});
end
hold off
grid
xlim([0 1])
title('X-Scaled & X-Shifted')
legend([hp{:}],'Location','best')

.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
参考
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)
