tag:www.mathworks.com,2005:/matlabcentral/fileexchange/feedMATLAB Central File Exchangeicon.pnglogo.pngMATLAB Central - File Exchange - type:Example product:"Symbolic Math Toolbox"User-contributed code library2014-11-23T08:57:42-05:0061100tag:www.mathworks.com,2005:FileInfo/365342012-05-04T10:03:48Z2014-10-14T10:52:28ZHPF - a big decimal classHigh precision floating point arithmetic, a new class written in MATLAB<p>Very often I see people asking for a tool that offers more than 16 digits or so of accuracy. MATLAB itself only allows you to use doubles or singles in standard arithmetic, so that is the normal limit. The fact is, most of the time, if you can't do it with a double, you are doing something wrong. Good practices of numerical analysis are worth far more than any high precision tool. Even so, there are times when you will have a use for a bit of extra precision. And some of you will just want to play in the huge number sandbox. While some of you may use tools like that written by Ben Barrowes, HPF is written purely in MATLAB, so no compiles are needed. For all of you, whatever your reasons, I offer HPF, a High Precision Floating point tool.
<br />In fact, the reason I wrote HPF was for my own purposes. I wanted to learn to use the classdef tools in MATLAB that were released a few years ago. As well, I wanted to try building such a tool as a natural extension of the VPI tools I wrote some time ago. And I wanted to learn some techniques for working in a high number of digits. The result is HPF.</p>
<p>There are a few ideas I've introduced for how HPF interacts with the user. For example, HPF can work in any number of decimal digits, as chosen by the user. You can set the number of digits as a default. Thus, if you want to always work in 30 decimal digits, with 2 guard digits on all computations, then type this at the command prompt:</p>
<p>DefaultNumberOfDigits 30 2</p>
<p>From now on, for you HPF will always work in a total of 32 decimal digits of precision, and report the top 30 digits, thus two guard digits will be used internally. For example, </p>
<p>pie = hpf('pi')
<br />pie =
<br />3.14159265358979323846264338328</p>
<p>exp(pie - 3)
<br />ans =
<br />1.15210724618790693014572854771</p>
<p>HPF will recall this state the next time you start MATLAB. You can override the default state by specifying a different number of digits though.</p>
<p>hpf('e',12)
<br />ans =
<br />2.71828182846</p>
<p>I've stored values as part of HPF for e and pi that are accurate to 500,000 digits. In fact, those numbers were generated by HPF itself.</p>
<p>Finally, for speed and efficiency, HPF stores all numbers in the form of Migits, which are bundles of decimal digits. This yields a huge bonus in the speed of multiplies, since conv is employed for that purpose. We can see them here:</p>
<p>pie.Migits
<br />ans =
<br /> [3141 5926 5358 9793 2384 6264 3383 2795]</p>
<p>The nice thing is that the use of Migits will be transparent to most users. But if you want a bit more speed in your multiples, then you can get a boost by typing this:</p>
<p>DefaultDecimalBase 6</p>
<p>From now on, HPF will employ base 1000000 migits internally, what I call 6-migits. The only problem is, you will be restricted from using numbers with more than 36000 decimal digits. Speed has a price.</p>
<p>Another nice use of HPF is to extract the exact decimal form that MATLAB uses to store its own numbers. For example, what number does MATLAB REALLY store internally when you type in something like 1.23?</p>
<p>hpf(1.23,55)
<br />ans =
<br />1.229999999999999982236431605997495353221893310546875000</p>
<p>Is HPF complete as it stands? Of course not. HPF currently represents nearly 7000 lines of MATLAB code, in the form of dozens of methods available for the class. As it is, you will find many hundreds of hours of work on my part, over the course of several years. But I've not yet written a huge number of things that might be useful to some people. For example: roots, eig, chol, det, rank, backslash, gamma, etc. And HPF offers no support for complex numbers. Even so, I hope that some will find this useful, if only to learn some of the tricks I've employed in the building thereof. Some of those tricks are described in HPF.pdf.</p>
<p>For example, multiplies are best done in MATLAB by conv. But divides take more work, so here I use a Newton scheme that employs only adds and multiplies, and is quadratically convergent. A similar trick is available for square roots.</p>
<p>Or, look into how my exponential function works. Here I've used a few tricks to enhance speed of convergence of the exponential series. Of course, there are obvious range reduction tricks, but I've gone an extra step there. I also employ a different way of summing the series for exponentials (as well as the sine and cosine series) that minimizes divides.</p>
<p>A lot of thought and research has gone into the methods of HPF. Those thoughts are captured in the HPFMod.pdf file, as enhanced by Derek O'Connor. Many thanks there. HPFMod.pdf is sort of a manual too, for those who want to truly understand the tool.</p>
<p>HPF will probably never be in what I consider to be in a final form, as I am sure there are a few bugs still unfound. Even so, the tool is working quite well on the thousands of tests I have performed. For those of you who try HPF out and do find a bug, please send me an e-mail and I will repair it immediately.</p>John D'Erricohttp://www.mathworks.com/matlabcentral/fileexchange/authors/679MATLAB 7.14 (R2012a)MATLABSymbolic Math ToolboxHPF should work in any MATLAB release that employs the classdef capability for user defined classes.64462223922725falsetag:www.mathworks.com,2005:FileInfo/330732011-09-29T16:46:19Z2014-10-03T18:47:20ZTriangle/Ray IntersectionFast vectorized triangle/ray intersection algorithm <p>Ray/triangle intersection using the algorithm proposed by MÃ¶ller and
<br />Trumbore (1997), implemented as highly vectorized MATLAB code.
<br />The algorithm can work with one and two sided surfaces, as well as, with
<br />infinite lines, rays (lines bounded on one side) and segments (lines bounded on
<br />both sides).
<br /> Input (all arrays in in Nx3, where N is number of vertices or rays):
<br /> orig : ray's origin
<br /> dir : ray's direction
<br /> vert0, vert1, vert2: vertices of the triangle</p>
<p> Output:
<br /> Intersect - boolean array of length N
<br /> t - distance from the ray origin to the intersection point in |dir|
<br /> u,v - barycentric coordinates of the intersection point units
<br /> xcoor - carthesian coordinates of the intersection point</p>
<p>In addition PointInsideVolume is 3D equivalent to 2D inpolygon function and can test if
<br />array of points is inside or outside any volume defined by the surface grid.</p>Jaroslaw Tuszynskihttp://www.mathworks.com/matlabcentral/fileexchange/authors/24252MATLAB 7.12 (R2011a)MATLABSymbolic Math Toolbox25058falsetag:www.mathworks.com,2005:FileInfo/407452013-03-11T21:30:47Z2013-03-11T21:30:47ZComparing different methods to solve an Inverted Pendulum problemA simple reporting tool that shows how you can model an inverted pendulum in a few methods.<p>In order to solve an inverted pendulum dynamics, you can select several methods:
<br />1. Solving Symbolic equations.
<br />2. Solveing a MATLAB ODE
<br />3. Constructing a Simulink model
<br />4. Designing the system using SimMechanics</p>
<p>This submission show how you can leverage the reporting tools that exist in the MATLAB environemnt in order to compare the solution of all these methods, and show the advantage of each one:
<br />1. Symbolic, complete solution using the Symbolic Math toolbox.
<br />2. Parameter sweep using monte carlo simulation for a MATLAB function.
<br />3. Running the same Simulink dynamic model for different friction values.
<br />4. Modeling the problem and not the equations, using SimMechanics.</p>
<p>In order to run the comparison, simply run the following command:
<br />report symbolic_simmech;</p>
<p>The report template contains examples and how-to do it yourself.</p>
<p>I would like to acknowledge Carlos Osorio, who created some of the files and models in this example.</p>Roni Peerhttp://www.mathworks.com/matlabcentral/fileexchange/authors/120105MATLAB 8.0 (R2012b)MATLAB Report GeneratorSimMechanicsSimulinkSimulink Report GeneratorSymbolic Math ToolboxMATLABfalsetag:www.mathworks.com,2005:FileInfo/390352013-01-04T20:43:32Z2013-01-04T20:43:32ZNumerical Inverse Laplace TransformNumerical approximation of the inverse Laplace transform for use with any function defined in "s".<p>This set of functions allows a user to numerically approximate an inverse Laplace transform for any function of "s". The function to convert can be passed in as an argument, along with the desired times at which the function should be evaluated. The output is the response of the system at the requested times. </p>
<p>For instance, consider a ramp function.
<br />f = @(s) 2/s^2;
<br />t = [1 2 3 4 5]';
<br />talbot_inversion(f, t) </p>
<p>The time response output is [2 4 6 8 10], as expected. </p>
<p>These methods can be used on problems of considerably more difficulty as well and are intended to approximate an inverse Laplace transform where an exact solution is unknown. </p>
<p>Two basic solvers (Euler and Talbot) are included, along with *symbolic* versions of those solvers. The symbolic solutions take substantially longer to calculate, but are capable of any desired accuracy. Also, the symbolic versions require the Symbolic Toolbox, whereas the basic versions do not. </p>
<p>Please see example_inversions.pdf or html/example_inversions.html to get started!</p>Tucker McClurehttp://www.mathworks.com/matlabcentral/fileexchange/authors/391702MATLAB 8.0 (R2012b)Symbolic Math ToolboxMATLABfalsetag:www.mathworks.com,2005:FileInfo/308982011-03-30T10:23:46Z2011-04-01T11:12:40Zpmap - Parameter Space Stability Mapping SuiteFinds the Hurwitz stability region in a parameter space of a continuous time system. <p>Given a continuous-time system with parameters, can we find the range (or intervals) of the parameters where the system is stable? </p>
<p>When the system model is written with the Laplacian transform, the question is equivalent to finding all the roots of a parameterized polynomial where the real parts of the roots are negative. Via orthant-based, sign-definite decomposition a set of "vertex polynomials" are created whereby such a test of stability can occur. Through iterative bisection of the parameter space, the region of stable parameters of the dynamic system can be constructed and viewed. </p>
<p>Examples are provided where the parameters are PID gains of a controller, though the parameters may also occur in the plant. Currently, the parameters must be real-valued, though the polynomial need not be real-valued. </p>
<p>For more detailed information, see the papers referenced in the H1 information and the readme. </p>
<p>Similar results are available for discrete-time systems, though these have not been included here. </p>
<p>The screenshot is the stability region of the polynomial:
<br />s^4 + (kd + kp + 10)*s^3 + (2*kp - 4*kd + 35)*s^2 + (50 - 23*kp - 18*kd*kp - 19*kd)*s + 35*kd*kp - 60*kp - 14*kd + 24.
</p>Michael Knaphttp://www.mathworks.com/matlabcentral/fileexchange/authors/57925MATLAB 7.11 (R2010b)Parallel Computing ToolboxSymbolic Math Toolboxlinewrap.m, File ID# 9099, is used if it is available. falsetag:www.mathworks.com,2005:FileInfo/89222005-11-02T18:32:44Z2005-11-03T12:17:23Zz-transform of 1D & 2D Savitzky-Golay Smoothing and Differentiation Filterz-transform of 1D & 2D Savitzky-Golay Smoothing and Differentiation Filter<p>Compute and plot 1D and 2D Savitzky-Golay smoothing and differentiation filters.</p>
<p>Savitzky-Golay (GS)Filters are polynomial-based filters frequently used for processing of 2D Images. </p>
<p>A good basic introdution to these filters is found on net at:
<br /><a href="http://research.microsoft.com/users/jckrumm/SavGol/SavGol.htm">http://research.microsoft.com/users/jckrumm/SavGol/SavGol.htm</a>.</p>
<p>The following MATLAB functions that compute GS-filters are available at the MATLAB File Exchange:
<br />File IDs [4038; 5661; 4270; 6121; 7003; 5556; 6047; 6151]</p>
<p>This zip-folder contains two functions: ztrans1d.m and ztrans2d.m that compute the z-transform of any GS filter and plot its amplitude spectrum.</p>
<p>Following is a demo of these functions in action for 1D and 2D GS-filters.</p>Abdulwahab Abokhodairhttp://www.mathworks.com/matlabcentral/fileexchange/authors/20889MATLAB 7.0.4 (R14SP2)Symbolic Math Toolbox40384270555656616047612161517003true