Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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-vpa_Matlab_Precision - Fatal编程技术网

精密matlab-vpa

精密matlab-vpa,matlab,precision,Matlab,Precision,我正在使用一种算法,它使用双曲线函数,为了从中获得更精确的结果,我需要提高精度,所以我想用vpa函数的方法来实现它,但我不太确定如何实现它。以下是一些进一步澄清情况的代码: x=18; %the hyperbolic relation is valid until x=18 cosh(x)^2-sinh(x)^2 ans = 1 x=19; %the hyperbolic relation is no longer valid cosh(x)^2-sinh(x)^2 ans = 0 使用VP

我正在使用一种算法,它使用双曲线函数,为了从中获得更精确的结果,我需要提高精度,所以我想用vpa函数的方法来实现它,但我不太确定如何实现它。以下是一些进一步澄清情况的代码:

x=18; %the hyperbolic relation is valid until x=18
cosh(x)^2-sinh(x)^2
ans = 1

x=19; %the hyperbolic relation is no longer valid
cosh(x)^2-sinh(x)^2
ans = 0
使用VPA功能:

a=vpa('cosh(40)',30); %the hyperbolic relation is valid beyond x=19
b=vpa('sinh(40)',30);
a^2-b^2
ans = 1.00008392333984375
现在的问题是,我不知道如何使用控制变量“x”从VPA获取值

我试过了,但没用:

x=40;
a=vpa('cosh(x)',x,30);
b=vpa('sinh(x)',30);
a^2-b^2

在进行符号数学或其他数学运算时,必须注意浮点之间的转换。在这种情况下,您需要将输入
x
转换为可变精度,然后再将其传递到
cosh
sinh
(否则,只有这些输入的输出才会转换为可变精度)。例如:

x = vpa(40,30);
a = cosh(x);
b = sinh(x);
a^2-b^2

返回预期的
1.0
。我不确定您在哪里找到了将
vpa
与字符串输入一起使用的方法,但该形式已不再使用(由于调用的函数不同,使用字符串甚至可能导致不同的结果)。还请注意,当前版本的Matlab中的默认设置为32。

x=40;a=vpa(cosh(x),30);不起作用?根据matlab文档,这应该行得通。@RobertStettler,我想这就是答案,OP只是没有使用正确的语法。想从你的评论中做出回答吗?@A.Donda:不太想。更重要的是,它是关于在正确的点从浮点转换到
vpa
。@horchler,看来你是对的。抱歉@RobertStettlerI在这里看到了它。你的方法也可以,但我把“x”作为一个控制变量的意思是把它的值从vpa函数中插入,就像是自动插入一样,因为我从前面的计算中得到了“x”,这是一个复数