MATLAB Answers

Error using sym/subsindex

5 views (last 30 days)
Susmit Kumar Sahu
Susmit Kumar Sahu on 9 Jul 2020
Answered: Devineni Aslesha on 22 Jul 2020
I need to make this code work.
Trying for 2 days, Please someone help me to debug this error.
Error displayed
clc
clear
Start = input("Enter the Start value: ");
End = input("Enter the End value: ");
grid_size = input("Enter the grid size: ");
np = input("Enter the number of input points: ");
x = zeros(1,np,'uint32');
y = zeros(1,np,'uint32');
i = 1;
while i <= np
x(i) = input("Coordinates of X value: ");
y(i) = input("Coordinates of y value: ");
i = i + 1;
end
j = 1;
px = zeros(1,np);
py = zeros(1,np);
syms j
for t =0:1:0.01
blending_function = (factorial(np)/factorial(j)*factorial(np-j)).*(t.^j).*(1-t).^(np-j))
px = symsum((blending_function.*x(j+1),j,0,np-1);
py = symsum(((factorial(np)/factorial(j)*factorial(np-j)).*(t.^j).*(1-t).^(np-j)).*y(j+1),j,0,np-1);
end
%px=(1-t).^3*x(1)+3*t.*(1-t).^2*x(2)+3*t.^2.*(1-t)*x(3)+t.^3*x(4);
%py=(1-t).^3*y(1)+3*t.*(1-t).^2*y(2)+3*t.^2.*(1-t)*y(3)+t.^3*y(4);
title("Bezier Curve for cloud points")
grid on
grid minor
plot(x,y);
hold
plot(px,py,'r');
xlabel('postition in x');
ylabel('position in y');
legend('Actual curve','Bezier Curve');
%axis([0 4.2 0 3.2]);

  3 Comments

KSSV
KSSV on 9 Jul 2020
To use symsum there should be a symolic object/ sym class.....there is no sym class in your code.
What is the series for which you want to get sum?
madhan ravi
madhan ravi on 9 Jul 2020
It’s so confusing, mind posting the latex equation?
Susmit Kumar Sahu
Susmit Kumar Sahu on 9 Jul 2020
Please help me rectifying now.

Sign in to comment.

Answers (1)

Devineni Aslesha
Devineni Aslesha on 22 Jul 2020
Hi Susmit
In the given code, the error is due to the presence of x(j+1) and y(j+1) that belongs to Class uint32. However, the Expression defining terms of series in symsum should be symbolic (Class: sym). Make sure what is the purpose of using x and y in your code and convert it to symbolic expression. If you remove x(j+1) and y(j+1), the code runs without any error.

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!