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 Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by