小编Ver*_*ian的帖子

用MATLAB找到三角函数的Minimax多项式逼近

我试图在MATLAB中使用remez交换算法找到正弦和余弦的minimax多项式近似.因为我正在实现IEEE-754浮点的正弦和余弦函数,所以需要精度到23位.

在这里使用此链接(参见第8页到第15页),给出了使用Mathematica和Maple查找多项式的指令,但是,我不确定如何为MATLAB推断这些方法.

根据表3,我需要使用5阶或6阶多项式来获得~23位(小数点后)的精度.

我计划首先将所有输入θ的范围缩小到-pi/4到+ pi/4之间,然后根据需要执行正弦或余弦函数(最终目标是实现exp(i*x)= cos( x)+ i*sin(x).

我也许可以自己遵循本文的说明,但我不知道如何在这里使用remez函数.另外,我不遵循为什么作者使用等式(6)(第9页),也不理解k的等式(第11页)是如何确定的(2796201来自哪里?)为什么定义我们希望最终改变为sin9x的多项式的形式= x + kx ^ 3 + x ^ 5*P(x ^ 2).

是否更好地使用firpm函数(因为remez已被弃用)?

谢谢,非常感谢所有帮助和指导,以及编辑,以确保我的问题可能得到最好的答案.

math floating-point matlab trigonometry

1
推荐指数
1
解决办法
3851
查看次数

将值分配给C中的动态二维数组时的分段错误

嗨,我正在用C编写程序,但是在运行程序时出现了分段错误.

我正在使用gcc进行编译,并且在编译时没有给出警告或错误.

我尝试使用gdb来跟踪段错误的来源,它将我引导到我将数据值分配给我的二维数组的行:array [row] [column] = datavalue;

当我运行我的程序存储3个数据值然后seg故障.它应该将数据存储在424行乘117列,但是在仅存储3个数据值之后它始终会出现故障.

我的代码如下(省略了一些细节):

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void allmem(float** fpdata,...);            // allocate memory header
void stored(float** fpdata,...);            // store data header
void countnumber(int* num1, int*num2,...);  // count header

int main()   // main() function
{
int numberofrows = 424; // number of rows
float** fpdata;         // two dimensional array fpdata of floats

allmem(fpdata,...);     // call allocate memory function
stored(fpdata,...);     // call function to store data
...
return 0;
} // main ()

// …
Run Code Online (Sandbox Code Playgroud)

c memory dynamic segmentation-fault

0
推荐指数
1
解决办法
1655
查看次数

Matlab如何将数字转换为二进制的单精度浮点表示

可能重复:
Matlab中数字的二进制表示

我正在使用matlab并希望将数字转换为7546.456124865单精度.

我已经使用了该single()命令,但我想获得单精度浮点的二进制文件.我该怎么做呢?

matlab

0
推荐指数
1
解决办法
4502
查看次数

无法获得C程序构建

我正在尝试执行此处找到的c程序.但是当我尝试在eclipse中构建它时,我会收到许多关于隐式声明的函数和不存在的访问寄存器的错误.我想知道是否有人可以运行此代码以及如何使其运行(程序,操作系统等)我在使用带有eclipse和gcc的ubuntu虚拟机的Windows机器上尝试执行此代码.

以下是Eclipse SDK中的错误列表(我修复了原始代码中的一些错误):

**** Build of configuration Debug for project nearpi ****

make all 
Building file: ../src/nearpi.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/nearpi.d" -MT"src/nearpi.d" -o "src/nearpi.o" "../src/nearpi.c"
../src/nearpi.c:465:1: warning: return type defaults to ‘int’ [-Wreturn-type]
../src/nearpi.c: In function ‘main’:
../src/nearpi.c:501:5: warning: implicit declaration of function ‘input’ [-Wimplicit-function-declaration]
../src/nearpi.c:532:9: warning: implicit declaration of function ‘nearPiOver2’ [-Wimplicit-function-declaration]
../src/nearpi.c:540:9: warning: implicit declaration of function ‘dbleCF’ [-Wimplicit-function-declaration]
../src/nearpi.c: At top level:
../src/nearpi.c:590:1: warning: return type …
Run Code Online (Sandbox Code Playgroud)

c eclipse compilation

0
推荐指数
1
解决办法
487
查看次数

在verilog中左移一个数字,只保留高位

我在verilog中有以下电汇:

wire [15:0] mywire;
wire [7:0] mywire_shifted
wire [4:0] shiftamount;
Run Code Online (Sandbox Code Playgroud)

我想将mywire左移一些,但只保留高8位:

assign mywire_shifted = (mywire << shiftamount) >> 8;
Run Code Online (Sandbox Code Playgroud)

有更清洁的方法吗?

也许是这样的:

assign {mywire_shifted,8'0} = mywire << shiftamount;
Run Code Online (Sandbox Code Playgroud)

hardware verilog hdl register-transfer-level

0
推荐指数
1
解决办法
384
查看次数