solve command returns sym instead of numerical answer
Mostrar comentarios más antiguos
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]
Respuestas (2)
Walter Roberson
el 30 de Oct. de 2012
1 voto
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
el 30 de Oct. de 2012
Editada: Star Strider
el 30 de Oct. de 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
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!