Error using sym/subsindex

조회 수: 2 (최근 30일)
Susmit Kumar Sahu
Susmit Kumar Sahu 2020년 7월 9일
답변: Devineni Aslesha 2020년 7월 22일
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
Susmit Kumar Sahu 2020년 7월 9일
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에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by