Trying a overlapping but piecewise plot
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
