Trying a overlapping but piecewise plot
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1174543/image.jpeg)
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
0 Commenti
Risposta accettata
Star Strider
il 31 Ott 2022
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 Commenti
Star Strider
il 31 Ott 2022
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')
.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!