Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. (20 pts) B-Spline. Code in MATLAB the B-Spline defined by the points in Probl

ID: 3604690 • Letter: 3

Question

3. (20 pts) B-Spline. Code in MATLAB the B-Spline defined by the points in Problem 1. Plot and print the provided points and the B-Spline on one figure. 4. (20 pts) Monomial least-squares. Code in MATLAB the least-squares estimation of a monomial of degree d using the n data 2%, ykl provided by the function y = sinx e-z? and computed with constant step in r from -1 and +1. Please plot and print out the points and fitting function for the following (n, d) pairs: (5,3), (10,3), (10,5). (This means you need to run your code with n = 5 and d = 3 and plot it, then run it again for n-10 and d= 3 and plot that, etc.)

Explanation / Answer

Here's some code snippets for MATLAB does B-spline curve evaluation for a degree-p B-spline curve with knot vector U at parameter value u with control point array C:

function S = bcurve_eval(u,p,U,C)

uspan = findKnotSpan(u,p,U);

Nu = getBasisFuncs(u,p,U,uspan);

S = zeros(1,numel(C(1,:)));

for i=0:p

index = uspan-p+i;

S = S + C(index+1,:) * Nu(i+1);

end

end

function i = findKnotSpan(u,p,U)

k = numel(U)-1;

n = k-p-1;

if u == U(n+1 +1)

i = n;

return

end

l = p +1;

h = n+1 +1;

i = floor((l+h)/2);

while u < U(i) || u >= U(i+1)

if u < U(i)

h = i;

else

l = i;

end;

i = floor((l+h)/2);

end

i = i-1;

end

function N = getBasisFuncs(u,p,U,i)

left = zeros(1,p+1);

right = zeros(1,p+1);

N = zeros(1,p+1);

N(1) = 1;

for j=1:p

left(j+1) = u - U(i+1-j +1);

right(j+1) = U(i+j +1) - u;

s = 0;

for r=0:j-1

temp = N(r +1) / (right(r+1 + 1) + left(j-r +1));

N(r +1) = s + right(r+1 +1) * temp;

s = left(j-r +1) * temp;

end

N(j +1) = s;

end

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote