solve command returns sym instead of numerical answer
Mostra commenti meno recenti
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]
Risposte (2)
Walter Roberson
il 30 Ott 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
il 30 Ott 2012
Modificato: Star Strider
il 30 Ott 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
Categorie
Scopri di più su Symbolic Math Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!