solve command returns sym instead of numerical answer

The code below is intended to return values for T for any number N and creates a a system of equations to do so.
clear
clc
n=input('enter n value :');
T=sym('T', [n 1]);
for x=1:n
if x==1
eqmatrix(x)=(0==2*T(x+1)-(2+1/(n^2))*T(x)+1/(4*n^2));
elseif 1<x && x<n
eqmatrix(x)=(0==T(x+1)+T(x-1)-(2+(1/(n^2)))*T(x)+1/(4*n^2));
elseif x==n
eqmatrix(x)=(0==2*T(x-1)-(2+1/(n^2))*T(x)+1/(4*n^2));
end
end
solve(eqmatrix)
This program returns a sym matrix instead of the numerical answers I was hoping for. What am I doing wrong?
enter n value :5
ans =
T1: [1x1 sym]
T2: [1x1 sym]
T3: [1x1 sym]
T4: [1x1 sym]
T5: [1x1 sym]

답변 (2개)

Walter Roberson
Walter Roberson 2012년 10월 30일

1 개 추천

solve() always returns symbolic answers, even if the results have no symbols in them. You may wish to use double() to convert to double precision values.
Star Strider
Star Strider 2012년 10월 30일
편집: Star Strider 2012년 10월 30일
It gives numeric answers. You simply aren't asking it to display them.
Ts = solve(eqmatrix)
then, since Ts is a structure, use:
Tn = structfun(@double,Ts)
to produce their double equivalents:
Tn =
250.0000e-003
250.0000e-003
250.0000e-003
250.0000e-003
250.0000e-003

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2012년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by