Variable x must be of data type double. It is currently of type sym. Check where the variable is assigned a value.
조회 수: 57 (최근 30일)
이전 댓글 표시
Hello,
I was wondering how I could change my variable 'x' to type double from syms. I've tried converting it to type double with x=double(x) and nothing has happened.
Help would be very appreciated!
U = [3,2,1;
0,1,2;
0,0,1]
b = [0;0;0]
x=backsub(A,b)
function x = backsub_syms(U,b)
n = length(b);
syms t
x=sym(zeros(n,1))
x(n)=sym('t')
b=(sym(b))
for i = n:-1:1
x(i)=b(i);
x(n)=sym('t')
if i<n
for j = n:-1:i+1
x(i)=x(i)-U(i,j)*x(j);
end
end
x(i)=x(i)/U(i,i);
end
end
Thanks for the help much appreciated!
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 9월 19일
편집: Ameer Hamza
2020년 9월 19일
You need to substitute a value for symbolic variable t to get a numeric value
U = [3,2,1;
0,1,2;
0,0,1];
b = [0;0;0];
syms t;
x = backsub_syms(U,b);
y = subs(x, t, 1) % t = 1
double(y)
function x = backsub_syms(U,b)
n = length(b);
syms t
x=sym(zeros(n,1))
x(n)=sym('t')
b=(sym(b))
for i = n:-1:1
x(i)=b(i);
x(n)=sym('t')
if i<n
for j = n:-1:i+1
x(i)=x(i)-U(i,j)*x(j);
end
end
x(i)=x(i)/U(i,i);
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!