Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab:将1x1 sym转换为双精度_Matlab - Fatal编程技术网

Matlab:将1x1 sym转换为双精度

Matlab:将1x1 sym转换为双精度,matlab,Matlab,我是MATLAB新手,我想将test(1x1 sym值)转换为双精度值 我该怎么做?这是我当前的代码: 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(

我是MATLAB新手,我想将test(1x1 sym值)转换为双精度值

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

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

函数[xn]=牛顿法(f,x0,h,步数)
%f是一个符号
%x0是起始值
%h是派生步长
%步骤。。多少次计算
xn=x0;i=0;
当我走着的时候
v=f(xn+h)-f(xn);
导数=v/h;
xn=xn-f(xn)/导数;
i=i+1;
输出=双精度(xn)%1它返回1x1 sym,无双精度
结束
我想你想要这个功能。用实际值替换符号变量

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

你试过双重(测试)?是的,但当我用牛顿法.m转换测试并返回测试时,它又是1x1 sym值。函数[xn]=牛顿法(f,x0,h,steps)%f是一个symfun%x0是起始值%h是推导步长%steps。。计算次数xn=x0;i=0;而ioutput!您的函数只返回
xn
,这仍然是一个符号。是的,我还必须转换步长计算。然后它将返回一个双精度。谢谢你的提示!:)