就一个简单循环10^9次的加法程序,我的电脑用matlab大概要算100分钟。那么用C++大概需要多长时间?fortran呢?此外,fortran和C++在数值计算方面哪... 就一个简单循环10^9次的加法程序,我的电脑用matlab大概要算100分钟。那么用C++大概需要多长时间?fortran呢?
此外,fortran和C++在数值计算方面哪个更快呢? 简洁地解释一下:
=================================
首先声明,Fortran / C是高级语言,MATLAB是解释型语言。

如果你的MATLAB程序有一个大循环,那么每次循环时MATLAB都要解释一次语句,因此你的100分钟当中,有相当一部分不是在运行程序,而是在解释程序。

Fortran / C只是在编译的时候解释一次,将程序转成机器可识别的代码。因此如果有大循环,就应该用Fortran / C。MATLAB只适用于小程序,也就算是个高级计算器。
=============================
其次,关于Fortran / C。都是高级语言,速度上不会有太大区别。

Fortran可以直接进行矩阵操作,因此可以直接把数学公式转换成语句。Fortran的意思就是FORmula TRANslator,适合于做数值计算。

C的优势是指针,因此适合于存在复杂数据结构的问题。但如果要用C实现矩阵操作,就必须自己写繁琐的循环。

明白了吗? 这种比较毫无意思
请你仔细看看matlab的介绍信息
MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation. Using the MATLAB product, you can solve technical computing problems faster than with traditional programming languages, such as C, C++, and Fortran.

You can use MATLAB in a wide range of applications, including signal and image processing, communications, control design, test and measurement, financial modeling and analysis, and computational biology. Add-on toolboxes (collections of special-purpose MATLAB functions, available separately) extend the MATLAB environment to solve particular classes of problems in these application areas.

MATLAB provides a number of features for documenting and sharing your work. You can integrate your MATLAB code with other languages and applications, and distribute your MATLAB algorithms and applications. Features include:

*

High-level language for technical computing
*

Development environment for managing code, files, and data
*

Interactive tools for iterative exploration, design, and problem solving
*

Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, and numerical integration
*

2-D and 3-D graphics functions for visualizing data
*

Tools for building custom graphical user interfaces
*

Functions for integrating MATLAB based algorithms with external applications and languages, such as C, C++, Fortran, Java™, COM, and Microsoft® Excel
另外我觉得速度不光取决于语言问题
我前一段时间写了一个程序,c#运行135s,matlab运行3.5s