Matlab:将1x1 sym转换为double

时间:2015-04-13 19:29:30

标签: matlab

我是MATLAB的新手,我希望将测试(1x1 sym值)转换为double值。

我该怎么做?这是我目前的代码:

function [ xn ] = newton_method( f, x0, h, steps ) 
%f is a symfun 
%x0 is the starting value 
%h is derivation-stepwidth
%steps.. how many calculations 
xn = x0; i = 0; 

while i < steps 
v = f(xn+h)-f(xn); 
derivation = v/h; 
xn = xn - f(xn)/derivation; 
i=i+1; 
output = double(xn) % it returns 1x1 sym and no double
end

1 个答案:

答案 0 :(得分:0)

我想你想要subs功能。您将符号变量替换为实际值

syms sym_a %a is now a symbolic variable
val_a = subs(sym_a,5.3) % we've replaced the symbolic a with number 5.3