matlab计算流函数,hanyeah

上面的网址不知道什么时候就打不开了,赶紧保存一份,要不想看都看不到了。

什么是流函数,什么是位函数(势函数),可以自己搜索。

说说我这里的应用场景。

空间放一些电荷,我们能够算出任意一点的电场强度——一个矢量,现在,我们能不能通过这些矢量来求出电场的等值线,即我可以通过给不同的值设置不同的颜色,最终得到电场线。这样得到的电场线不会有偏差,而用矢量一步一步画出来的电场线必然会有偏差。

Q: How to compute a streamfunction?

© Kirill Pankratov, Ph. D. (kirill@plume.mit.edu)

Department of Earth, Atmospheric & Planetary Sciences,

Massachusetts Institute of Technology, Cambridge, MA, 02139

(posted on comp.soft-sys.matlab, 1994-03-07)

Hi,

Although this question appears for the first time to my knowledge I believe it can be of rather general interest.

The streamfunction (and also the velocity potential) are rather fun-damental concepts for anybody who is dealing with fluid dynamics or geosciences, like power spectrum for signal processing.

The Mathwolks (I mean the folks from The Mathworks) could be surprised how many of the MATLAB users are oceanographers, meteorologists, geophysisists and not only electrical engineers or signal processors (no offence for the latter). So probably The Mathwork should learn at least some fundamentals about it and include the most general operations from these fields in its library.

Does anybody agree with this? ...

Anyway, here I present the program "flowfun" which calculates the streamfunction psi and the velocity potential phi (that is the velocity field is a scalar and vector product of the gradient operator and the potential and the streamfunction correspondingly):u = d(phi)/dx,   v = d(phi)/dy  for potential flows,

u = -d(psi)/dy,  v = d(psi)/dx  for solenoidal flows.These potentials are computed by integrating the velocities given by matrices u, v using Simpson rule summation. To do this the routine "cumsimp" is added. This routine is actually of much more general application, than the "flowfun" - is is general cumulative integrator - a little bit similar to "cumsum" but much more accurate (for continuous functions) and starting from zero. I think MATLAB should have had something like this long ago it would be useful for anybody dealing with continuous fields. See HELP for additional information.

Now back to "flowfun".

To get the feeling what it is all about try the following script:e = 2; g = 1;

[x,y] = meshgrid(0:20,0:15);  % This makes regular grid

u = e*x-g*y;                  % Linear velocity field

v = g*x-e*y;

[phi,psi] = flowfun(u,v);  % Here comes the potential and streamfun.

contour(phi,20,'--r')   % Contours of potential

hold on

contour(psi,20,'-g')    % Contours of streamfunction

quiver(u,v,'w')         % Now superimpose the velocity field

% Now see the meaning of these potentials?

If you want the streamfunction only, use

psi = flowfun(u,v,'-')

(or psi = flowfun(u,v,'psi') or psi = flowfun(u,v,'stream') ).I would appreciate any comments and suggestions about these routines. Regards, Kirill.

And now the code itself (flowfun.m and cumsimp.m).==================================  save as   flowfun.m  =========

function  [phi,psi] = flowfun(u,v,flag)

% FLOWFUN  Computes the potential PHI and the streamfunction PSI

%     of a 2-dimensional flow defined by the matrices of velocity

%     components U and V, so that

%

%           d(PHI)    d(PSI)          d(PHI)    d(PSI)

%      u =  -----  -  ----- ,    v =  -----  +  -----

%            dx        dy              dx        dy

%

%     For a potential (irrotational) flow  PSI = 0, and the laplacian

%     of PSI is equal to the divergence of the velocity field.

%     A non-divergent flow can be described by the streamfunction

%     alone, and the laplacian of the streamfunction is equal to%     vorticity (curl) of the velocity field.

%     The stepsizes dx and dy are assumed to equal unity.

%   [PHI,PSI] = FLOWFUN(U,V), or in a complex form

%   [PHI,PSI] = FLOWFUN(U+iV)

%     returns matrices PHI and PSI of the same sizes as U and V,

%     containing potential and streamfunction given by velocity

%     components U, V.

%     Because these potentials are defined up to the integration

%     constant their absolute values are such that

%     PHI(1,1) = PSI(1,1) = 0.

%     If only streamfunction is needed, the flag can be used:

%   PSI = FLOWFUN(U,V,FLAG), where FLAG can be a string:

%     '-', 'psi', 'streamfunction' (abbreviations allowed).

%     For the potential the FLAG can be  '+', 'phi', 'potential'.

%  Uses command CUMSIMP (Simpson rule summation).

%  Kirill K. Pankratov, March 7, 1994.

% Check input arguments .............................................

issu=0; issv=0; isflag=0;    % For input checking

isphi = 1; ispsi = 1;        % Is phi and psi to be computed

if nargin==1, issu = isstr(u); end

if nargin==2, issv = isstr(v); end

if nargin==1&~issu, v=imag(u); end

if issv, flag = v; v = imag(u); isflag = 1; end

if nargin==0|issu            % Not enough input arguments

disp([10 '  Error: function must have input arguments:'...

10 '  matrivces  U and V  (or complex matrix W = U+iV)' 10 ])

return

end

if any(size(u)~=size(v))     % Disparate sizes

disp([10 '  Error: matrices U and V must be of equal size' 10])

return

end

if nargin==3, isflag=1; end

u = real(u);

% Check the flag string . . . . . . . .

Dcn = str2mat('+','potential','phi');

Dcn = str2mat(Dcn,'-','streamfunction','psi');

if isflag

lmin = min(size(flag,2),size(Dcn,2));

flag = flag(1,1:lmin);  A = flag(ones(size(Dcn,1),1),1:lmin)==Dcn(:,1:lmin);

if lmin>1, coinc = sum(A'); else, coinc = A'; end

fnd = find(coinc==lmin);

if fnd~=[], if fnd<4, ispsi=0; else, isphi=0; end, end

end

phi = [];        % Create output

psi = [];

lx = size(u,2);  % Size of the velocity matrices

ly = size(u,1);

% Now the main computations .........................................

% Integrate velocity fields to get potential and streamfunction

% Use Simpson rule summation (function CUMSIMP)

% Compute potential PHI (potential, non-rotating part)

if isphi

cx = cumsimp(u(1,:));  % Compute x-integration constant

cy = cumsimp(v(:,1));  % Compute y-integration constant

phi = cumsimp(v)+cx(ones(ly,1),:);

phi = (phi+cumsimp(u')'+cy(:,ones(1,lx)))/2;

end

% Compute streamfunction PSI (solenoidal part)

if ispsi

cx = cumsimp(v(1,:));  % Compute x-integration constant

cy = cumsimp(u(:,1));  % Compute y-integration constant

psi = -cumsimp(u)+cx(ones(ly,1),:);

psi = (psi+cumsimp(v')'-cy(:,ones(1,lx)))/2;

end

% Rename output if need only PSI

if ~isphi&ispsi&nargout==1, phi = psi; end

=========================== end  flowfun.m ======================

============================ save as  cumsimp.m =================

function  f = cumsimp(y)

% F = CUMSIMP(Y)    Simpson-rule column-wise cumulative summation.

%       Numerical approximation of a function F(x) such that

%       Y(X) = dF/dX.  Each column of the input matrix Y represents

%       the value of the integrand  Y(X)  at equally spaced points

%       X = 0,1,...size(Y,1).

%       The output is a matrix  F of the same size as Y.

%       The first row of F is equal to zero and each following row

%       is the approximation of the integral of each column of matrix

%       Y up to the givem row.

%       CUMSIMP assumes continuity of each column of the function Y(X)

%       and uses Simpson rule summation.

%       Similar to the command F = CUMSUM(Y), exept for zero first

%       row and more accurate summation (under the assumption of

%       continuous integrand Y(X)).

%

%    See also CUMSUM, SUM, TRAPZ, QUAD

%  Kirill K. Pankratov, March 7, 1994.

% 3-points interpolation coefficients to midpoints.

% Second-order polynomial (parabolic) interpolation coefficients

% from  Xbasis = [0 1 2]  to  Xint = [.5 1.5]

c1 = 3/8; c2 = 6/8; c3 = -1/8;

% Determine the size of the input and make column if vector

ist = 0;         % If to be transposed

lv = size(y,1);

if lv==1, ist = 1; y = y(:); lv = length(y); end

f = zeros(size(y));

% If only 2 elements in columns - simple sum divided by 2

if lv==2

f(2,:) = (y(1,:)+y(2))/2;

if ist, f = f'; end   % Transpose output if necessary

return

end

% If more than two elements in columns - Simpson summation

num = 1:lv-2;

% Interpolate values of Y to all midpoints

f(num+1,:) = c1*y(num,:)+c2*y(num+1,:)+c3*y(num+2,:);

f(num+2,:) = f(num+2,:)+c3*y(num,:)+c2*y(num+1,:)+c1*y(num+2,:);

f(2,:) = f(2,:)*2; f(lv,:) = f(lv,:)*2;

% Now Simpson (1,4,1) rule

f(2:lv,:) = 2*f(2:lv,:)+y(1:lv-1,:)+y(2:lv,:);

f = cumsum(f)/6;  % Cumulative sum, 6 - denom. from the Simpson rule

if ist, f = f'; end     % Transpose output if necessary

============================= end  cumsimp.m =================

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441916.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【51Nod - 1279】 扔盘子(思维)(on-p会超时)

题干&#xff1a; 有一口井&#xff0c;井的高度为N&#xff0c;每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘&#xff0c;如果圆盘的宽度大于井在某个高度的宽度&#xff0c;则圆盘被卡住&#xff08;恰好等于的话会下去&#xff09;。 盘子有几种命运&#xff1a;1、…

java 内部类私有成员 能访问,为什么外部Java类可以访问内部类私有成员?

HUX布斯如果您想隐藏内部类的私有成员&#xff0c;您可以与公共成员定义一个接口&#xff0c;并创建一个实现此接口的匿名内部类。下面的例子&#xff1a;class ABC{private interface MyInterface{void printInt();}private static MyInterface mMember new MyInterface(){pr…

【HDU - 6290】 奢侈的旅行 (对题目预处理 + DIjkstra最短路)

题干&#xff1a; 高玩小Q不仅喜欢玩寻宝游戏&#xff0c;还喜欢一款升级养成类游戏。在这个游戏的世界地图中一共有nn个城镇&#xff0c;编号依次为11到nn。 这些城镇之间有mm条单向道路&#xff0c;第ii 条单项道路包含四个参数ui,vi,ai,biui,vi,ai,bi&#xff0c;表示一条…

数学建模matlab推荐,推荐数学建模matlab方法整理 - 图文

disp()函数的常见用法1、显示字符串 >> disp(sqrt(2)) sqrt(2)将要显示的字符串必须放在单引号里面&#xff01;&#xff01;&#xff01; 2、显示结果 >> disp(sqrt(2)) 1.41423、显示多个字符>> disp([sqrt(2),num2str(sqrt(2))]) sqrt(2)1.4142格式必须如…

【POJ - 3321】 Apple Tree(dfs序 + 线段树维护 或 dfs序 + 树状数组维护)

题干&#xff1a; There is an apple tree outside of kakas house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree. The tree has N forks which are connected by branches. …

gjr garch Matlab,基于Copula-ARIMA-GJR-GARCH模型的股票指数相关性分析

摘要&#xff1a;当资产收益率分布较为复杂时,研究它们之间的相关关系就变得较为困难。特别是股票市场中资产的收益率分布非正态时,我们几乎不可能去精确模拟几种资产收益率之间的联合分布函数。然而Copula函数恰恰可以解决这类问题。Copula函数是用来描述随机变量间相依结构的…

【HDU - 3974】 Assign the task (dfs序 + 线段树维护 区间更新+ 单点查询)

题干&#xff1a; There is a company that has N employees(numbered from 1 to N),every employee in the company has a immediate boss (except for the leader of whole company).If you are the immediate boss of someone,that person is your subordinate, and all hi…

php 插件 代码架构,php反射机制详以及插件架构实例详解

1。用途&#xff1a;该扩展分析php程序&#xff0c;导出或提取出关于类、方法、属性、参数等的详细信息&#xff0c;包括注释。Reflection可以说是对php库函数&#xff1a;“Classes/Objects 类&#xff0f;对象函数”的一个扩展。主要用在通过程序检测现有php程序内部关于类、…

【HDU - 1540】 Tunnel Warfare (线段树进阶操作 区间合并+ 单点更新+ 最长覆盖区间查询 )

题干&#xff1a; During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was …

php扩展包安装了为啥没加载,已安装PHP扩展但未加载

我正在尝试安装php的ssh2扩展,并且有一点点困难.文件在那里,它只是没有加载到PHP.首先,我安装了ssh2&#xff1a;aptitude install libssh2-1-dev libssh2-php(对于它的价值,我在Nginx上运行Ubuntu 12.04.)我可以看到使用modules命令加载ssh2&#xff1a;php -m |grep ssh2ssh2…

【HDU - 1166】敌兵布阵 (线段树模板 单点更新+ 区间查询)

题干&#xff1a; C国的死对头A国这段时间正在进行军事演习&#xff0c;所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段&#xff0c;所以每个工兵营地…

php中获取本月第二天,php第二天

//heredoc方式,可以保存长文本 <<<$str <<长文本EOTS;header("Content-Type:text/html;charsetutf-8"); //防止乱码0 1 2 3 4 5 十进制0 1 10 11 100 101 二进制十进制专二进制除二取余二进制专十进制1011*2*20*2*1(1*2/2)5;120 0 1 0 16 3 211111$a…

【HDU - 1754】I Hate It (线段树模板 单点覆盖更新+区间最大值查询)

题干&#xff1a; 很多学校流行一种比较的习惯。老师们很喜欢询问&#xff0c;从某某到某某当中&#xff0c;分数最高的是多少。 这让很多学生很反感。 不管你喜不喜欢&#xff0c;现在需要你做的是&#xff0c;就是按照老师的要求&#xff0c;写一个程序&#xff0c;模拟老…

php微信上传头像,微信小程序怎么上传头像

这次给大家带来的是微信小程序 上传头像的实例详解&#xff0c;最近在做微信小程序上传头像和上传照片功能就随手写一下代码&#xff0c;这篇文章就给大家好好分析一下。上传头像html&#xff1a;头像JS代码// 切换头像changeAvatar: function () {var that this;// var child…

【HDU - 1698】 Just a Hook(线段树模板 区间覆盖更新(laz标记) + 区间和查询 )

题干&#xff1a; In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. Now Pudge wants to do some operations on the hoo…

反序列化 php R类型,pikachu-PHP反序列化、XXE、SSFR

一、PHP反序列化1.1概述在理解这个漏洞前,你需要先搞清楚php中serialize()&#xff0c;unserialize()这两个函数。序列化serialize()序列化说通俗点就是把一个对象变成可以传输的字符串,比如下面是一个对象:class S{public $test"pikachu";}$snew S(); //创建一个对象…

【POJ - 3468 】 A Simple Problem with Integers (线段树模板 区间更新 + 区间和查询)(不能树状数组或差分数组)

题干&#xff1a; You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. I…

php向下滑动,js如何判断鼠标滚轮是向下还是向上滚动

判断鼠标滚轮是向上或向下滚动&#xff0c;不同的浏览器的判别方式是不一样的&#xff0c;当前比较流行的浏览器有 IE&#xff0c;Opera&#xff0c;Safari&#xff0c;Firefox&#xff0c;Chrome&#xff0c;在这个问题上Firefox和其他浏览器的实现方式是不一样的。现在通过一…

学习php技巧,对初学者非常有用的PHP技巧

对初学者非常有用的PHP技巧131415161718function add_to_cart($item_id , $qty){if(!is_array($item_id)){$_SESSION[cart][$item_id] $qty;}else{foreach($item_id as $i_id > $qty){$_SESSION[cart][$i_id] $qty;}}}add_to_cart( IPHONE3 , 2 );add_to_cart( array(IPHO…

【51nod - 1065】 最小正子段和( 前缀和排序 )

题干&#xff1a; N个整数组成的序列a11,a22,a33,…,ann&#xff0c;从中选出一个子序列&#xff08;aii,ai1i1,…ajj&#xff09;&#xff0c;使这个子序列的和>0&#xff0c;并且这个和是所有和>0的子序列中最小的。 例如&#xff1a;4&#xff0c;-1&#xff0c;5&a…