How to plot 2 graphs with input as a range and join them together?

조회 수: 1 (최근 30일)
iicecont
iicecont 2021년 9월 30일
댓글: Alan Stevens 2021년 9월 30일
Here is the equation I'm trying to write a code which is b-spline curve
Below is the code I've written where p0-p3 is my first set to substitute in equation, and p1-p4 is my second set :
p0=0;
p1=6;
p2=1;
p3=3;
p4=3;
t=[0:0.01:1];
x1 = (1/6)*[((((-t).^3)+(3*(t.^2))-(3*t)+1)*p0)+(((3*(t.^3))-(6*(t.^2))+ 4)*p1)+(((-3*(t.^3)) + (3*(t.^2)) + (3*t) +1)*p2)+((t.^3)*p3)];
x2 = (1/6)*[((((-t).^3)+(3*(t.^2))-(3*t)+1)*p1)+(((3*(t.^3))-(6*(t.^2))+ 4)*p2)+(((-3*(t.^3)) + (3*(t.^2)) + (3*t) +1)*p3)+((t.^3)*p4)];
figure
plot(t,x1)
hold on
plot(t,x2)
I don't know how to join the graph and I'm not sure if my code is correct if i don't use for loop for my input t. Appreciate for any help

답변 (1개)

Alan Stevens
Alan Stevens 2021년 9월 30일
Like this
p0=0;
p1=6;
p2=1;
p3=3;
p4=3;
t=[0:0.01:1];
x1 = (1/6)*[((((-t).^3)+(3*(t.^2))-(3*t)+1)*p0)+(((3*(t.^3))-(6*(t.^2))+ 4)*p1)+(((-3*(t.^3)) + (3*(t.^2)) + (3*t) +1)*p2)+((t.^3)*p3)];
x2 = (1/6)*[((((-t).^3)+(3*(t.^2))-(3*t)+1)*p1)+(((3*(t.^3))-(6*(t.^2))+ 4)*p2)+(((-3*(t.^3)) + (3*(t.^2)) + (3*t) +1)*p3)+((t.^3)*p4)];
figure
plot(t,x1,t+1,x2)
  댓글 수: 1
Alan Stevens
Alan Stevens 2021년 9월 30일
Alternatively, you could use Matlab's polyval function:
c1 = [-1 3 -3 1]/6;
c2 = [3 -6 0 4]/6;
c3 = [-3 3 3 1]/6;
c4 = [1 0 0 0]/6;
x = @(t,p) polyval(c1,t)*p(1) + polyval(c2,t)*p(2) + polyval(c3,t)*p(3) + polyval(c4,t)*p(4);
p = [0 6 1 3 3];
t=0:0.01:1;
x1 = x(t,p(1:4));
x2 = x(t,p(2:5));
plot(t,x1,t+1,x2)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by