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 日

1 投票

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 ExchangeSymbolic 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