scientific-computing

Mixed integer programming: variable assignment per condition (if then else)

不想你离开。 提交于 2020-01-03 05:20:10
问题 I am relatively new to (mixed) integer programming and got stuck with the formulation of a constraint. In my simplified model I have one Parameter and two Variables that are positive Reals having the value 321 as upper bound. The logic I want to express is here: if Parameter > Variable1: Variable2 = Variable1 else: Variable2 = Parameter **edit** (while Variable1 is always >= Variable2) Is it actually possible to describe this using linear in(equalities)? If it helps: For the implementation I

naming of physical quantities in python

被刻印的时光 ゝ 提交于 2020-01-02 10:18:02
问题 I would like to establish a good naming scheme for physical/mathematical quantities used in my simulation code. Consider the following example: from math import * class GaussianBeamIntensity(object): """ Optical intensity profile of a Gaussian laser beam. """ def __init__(self, intensity_at_waist_center, waist_radius, wavelength): """ Arguments: *intensity_at_waist_center*: The optical intensity of the beam at the center of its waist in W/m^2 units. *waist_radius*: The radius of the beam

Use if clause in arrayfun in Octave/Matlab

China☆狼群 提交于 2020-01-02 04:05:15
问题 Is it possible to use "if" in arrayfun like the following in Octave? a = [ 1 2; 3 4]; arrayfun(@(x) if x>=2 1 else 0 end, a) And Octave complains: >>> arrayfun(@(x) if x>=2 1 else 0 end, a) ^ Is if clause allowed in arrayfun? 回答1: In Octave you can't use if/else statements in an inline or anonymous function in the normal way. You can define your function in it's own file or as a subfunction like this: function a = testIf(x) if x>=2 a = 1; else a = 0; end end and call arrayfun like this:

Reproducibility in scientific programming

怎甘沉沦 提交于 2019-12-31 08:38:09
问题 Along with producing incorrect results, one of the worst fears in scientific programming is not being able to reproduce the results you've generated. What best practices help ensure your analysis is reproducible? 回答1: I'm a software engineer embedded in a team of research geophysicists and we're currently (as always) working to improve our ability to reproduce results upon demand. Here are a few pointers gleaned from our experience: Put everything under version control: source code, input

Writing robust and “modern” Fortran code

梦想与她 提交于 2019-12-29 10:08:48
问题 In some scientific environments, you often cannot go without FORTRAN as most of the developers only know that idiom, and there is lot of legacy code and related experience. And frankly, there are not many other cross-platform options for high performance programming (C++ would do the task, but the syntax, zero-starting arrays, and pointers are not compatible with some people). So, let's assume a new project must use Fortran 90, but I want to build the most modern software architecture out of

Writing robust and “modern” Fortran code

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-29 10:08:23
问题 In some scientific environments, you often cannot go without FORTRAN as most of the developers only know that idiom, and there is lot of legacy code and related experience. And frankly, there are not many other cross-platform options for high performance programming (C++ would do the task, but the syntax, zero-starting arrays, and pointers are not compatible with some people). So, let's assume a new project must use Fortran 90, but I want to build the most modern software architecture out of

plotting a parabola within part of a repeating signal using numpy

半城伤御伤魂 提交于 2019-12-22 11:28:05
问题 I have a repeating signal that varies a little bit with each cycle of a process that repeats roughly every second, though the duration and the contents of each cycle vary from each other a little bit within some parameters. There are a thousand x,y coordinates for every second of my signal data. A small, but important, segment of the data within each cycle is corrupted, and I want to replace each corrupted segment with an upward facing parabola. For each data segment that needs to be replaced

How to set a unified seed for random number generators in MATLAB?

会有一股神秘感。 提交于 2019-12-22 11:26:31
问题 I'm writing code and using existing functions from MATLAB. What if these functions use random number generators. Is there a way I can fix the seed of these functions without having to change their code ? Is there a command in MATLAB that does this ? 回答1: Normally code would use Matlab's built-in random number generator. You can seed it with the following: rng = RandStream.getDefaultStream; rng.reset(your_seed_value_here); One could also create RandStream objects and use them (thereby avoiding

Solving nonlinear equations numerically

主宰稳场 提交于 2019-12-20 20:38:19
问题 I need to solve nonlinear minimization (least residual squares of N unknowns) problems in my Java program. The usual way to solve these is the Levenberg-Marquardt algorithm. I have a couple of questions Does anybody have experience on the different LM implementations available? There exist slightly different flavors of LM, and I've heard that the exact implementation of the algorithm has a major effect on the its numerical stability. My functions are pretty well-behaved so this will probably

Plotting log-binned network degree distributions

自作多情 提交于 2019-12-20 11:01:31
问题 I have often encountered and made long-tailed degree distributions/histograms from complex networks like the figures below. They make the heavy end of these tails, well, very heavy and crowded from many observations: However, many publications I read have much cleaner degree distributions that don't have this clumpiness at the end of the distribution and the observations are more evenly-spaced. ! How do you make a chart like this using NetworkX and matplotlib ? 回答1: Use log binning (see also)