开发者

Translating Fortran Code to a Formula

开发者 https://www.devze.com 2023-03-11 00:31 出处:网络
I want to test some parts of my fortran code. I know that there is a command \"FortranForm\" for mathematica

I want to test some parts of my fortran code. I know that there is a command "FortranForm" for mathematica that does the reverse. If there is something else online that would be great also.

Is there something like this for easy cases of Fortran Code? For example what i want to convert right now is: result= exp((-0.5)*开发者_如何学运维((delta_w/delta)*(delta_w/delta)))


I've done this before with Mathematica v6 to help me understand a Fortran IV function, and the only way I found was by systematically replacing the Fortran constructs with Mathematica ones by hand. While not necessary in your case, Mathematica has both Goto and Label. For the longer functions, this requires some discipline, but is doable. In your case, the translation is quite easy; it is simply

Exp[ -0.5*(deltaw/delta)^2]

BTW, in your code (delta_w/delta)*(delta_w/delta) can be simplified to (delta_w/delta)**2.

Alternatively, if you are just interested in testing the code itself and you have v8, compile the function into a dynamic library, and use the new Wolfram LibraryLink feature to access it from inside of Mathematica. This functionality presupposes that your using C, and while I know it is possible to combine programs that use both languages, I have not done it. So, this option is not for the faint of heart, but it could give interesting results.


A method that sometimes works, though alas not in this example, is as follows.

(1) Mouse over the '+' at the top left of the next cell location. A pop-up will say "Choose how to enter input". Left-click mouse.

(2) On drop-down menu select "Free-form input".

(3) You should now see an '=' sign inside an orange box to the left of the cell. Enter your input and evaluate it. You might want to wrap it in Unevaluated[] so as not to perform actual computations.

A pane will appear below the input, with the result.

Translating Fortran Code to a Formula

Not so useful in this instance, but sometimes one gets closer to the mark.

Daniel Lichtblau


This is not a good solution, but often the easiest way is to interpret the formula as TraditionalForm, possibly editing it first to fix problems such as underscores being interpreted as patterns. You can automate some of this editing using StringReplace.

This solution might be faster and easier for small formulas than implementing something more complicated. After all the main issue (and sometimes the only one) is to somehow interpret f(x) as a function rather than multiplication.

Make a TradinionalForm cell (new cell, ctrl-shift-t), paste your formula, then evaluate it.

0

精彩评论

暂无评论...
验证码 换一张
取 消