solve command returns sym instead of numerical answer
Afficher commentaires plus anciens
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]
Réponses (2)
Walter Roberson
le 30 Oct 2012
1 vote
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
le 30 Oct 2012
Modifié(e) : Star Strider
le 30 Oct 2012
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
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!