Error using sym/subsindex

2 次查看(过去 30 天)
Susmit Kumar Sahu
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 个评论
madhan ravi
madhan ravi 2020-7-9
It’s so confusing, mind posting the latex equation?
Susmit Kumar Sahu
Please help me rectifying now.

请先登录,再进行评论。

回答(1 个)

Devineni Aslesha
Devineni Aslesha 2020-7-22
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.

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by