Tag Info

Hot answers tagged

23

Note: If you're using this package, please let us know how! Understanding how people use it helps us improve it in the right areas. There is a new cross platform package for this, called MATLink. It allows calling MATLAB functions seamlessly, directly from Mathematica, as well as transferring data between the two systems. See below for a small ...


17

There is the ToMatlab package that will convert Mathematica expressions to MATLAB equivalents. For example: <<ToMatlab` Expand[(x + Log@y)^5] // ToMatlab (* x.^5+5.*x.^4.*log(y)+10.*x.^3.*log(y).^2+10.*x.^2.*log(y).^3+5.* ... x.*log(y).^4+log(y).^5; *) It even conveniently breaks it using ... and can also convert matrices: RandomInteger[5, ...


15

Based on the MATLAB documentation, it would appear that this is accomplished by simple zero-filling. As such, you can obtain the same result in Mathematica using Fourier[PadRight[list, n, 0.], FourierParameters -> {1, -1}] where list is your signal and n is the desired length. For a multidimensional FFT, replace n with {n1, n2, ...}, where n1, n2, ...


11

I did a direct translation from Matlab file logspace.m with additional Mathematica minor touches. Mathematica Function logspace[d1_?(Element[#, Reals] &), dd2_?(Element[#, Reals] &), n_?(IntegerQ[#] && # > 0 &)] := Module[{d2 = dd2, i}, If[d2 == Pi, d2 = Log[10, d2]]; Flatten@{Table[10^(d1 + ...


9

You could try something like the following. bounded[Indeterminate] := $MaxMachineNumber; bounded[x_?NumericQ] := x This gives a very large number instead of Indeterminate so NMinimize keeps searching. NMinimize[bounded[J[{θ0, θ1, θ2}, X1, y1]], {θ0, θ1, θ2}] (* {0.203498, {θ0 -> -25.1613, θ1 -> 0.206231, θ2 -> 0.201471}} *) Incidentally, ...


9

If you make all the component parts matrices, you can use ArrayFlatten c = {{{{1}}, {{2, 3, 4}}}, {{{5}, {9}}, {{6, 7, 8}, {10, 11, 12}}}}; c // MatrixForm ArrayFlatten[c] // MatrixForm


8

My take: toward[p1_, p2_, v_: .05] := p1 + v Normalize[p2 - p1]; {n, r} = {4, 3}; DynamicModule[{pts, history}, pts = r {Cos[#], Sin[#]} & /@ Range[2 Pi/n, 2 Pi, 2 Pi/n]; history = {pts}; Print[Dynamic[ListPlot[Transpose@history, AspectRatio -> Automatic, Joined -> True, PlotStyle -> Directive[Thick, CapForm["Round"]], ...


8

I don't belive there is a build in function for this, however you can easily do it using Range fSpace[min_, max_, steps_, f_: Log] := InverseFunction[f] /@ Range[f@min, f@max, (f@max - f@min)/(steps - 1)] Inverse functions are being used so it'll give warnings in cases where you should be cautius, however it works for Log and other invertible ...


7

I'll leave this up on GitHub, but I won't maintain the port. I recommend using MATLink instead. There's a package on the Wolfram Library Archive called mEngine that allows calling MATLAB from Mathematica. What it can do is: execute arbitrary MATLAB commands and retrieve their output as a string transfer array variables between Mathematica and MATLAB ...


6

If you want to translate Matlab code into Mathematica, my advice is - don't! As programming languages, the two are very different and an idiom that works well in one is unlikely to work well in the other. A fundamental theorem theorem in discrete dynamics states that if there's an attractive orbit, then it must attract at least one critical point. Thus, ...


6

There are already good explanations about how the restructuring of the nested arrays given as input to cell2mat can be done in Mathematica. I couldn't resist to mention the following, though: The main purpose of the matlab function cell2mat is to convert from so called cell arrays to "normal" matlab matrices, where cell arrays correspond roughly to "normal" ...


5

Sorry I can't make sense of your Matlab code - too many nested Ifs. I don't know whether I've adapted belisarius' answer correctly: point = RandomInteger[100, {3}]; triangle = RandomInteger[100, {3, 3}] ; lines = Subsets[triangle, {2}]; nline[{start_, end_}, pt_] := Module[{param = ((pt - start).(end - start))/Norm[end - start]^2}, N@{pt, start + ...


4

Might try without approximate values. To do this, instead use numericValues = {Vphrms -> 230, Vlinerms -> Sqrt[3] 230, \[Omega] -> 2 \[Pi] 50, L1 -> 23*10^-4, L2 -> 93*10^-5, Cf -> 10*10^-6, Co -> 600*10^-6, rd -> 3/10, r1 -> 1/5, r2 -> 1/5, Dd -> 623324/1000000, Dq -> 246624/10000000, Vdc -> 650, I1d ...


3

You can use the powerful second argument of Flatten (see this answer by Leonid for an explanation) to do most of the work and finally partition it to the correct size. I'll use BoLe's example too: c = {{{1}, {2, 3, 4}}, {{{5}, {9}}, {{6, 7, 8}, {10, 11, 12}}}}; With[{m = Flatten[c, {{1}, {3, 2}}]}, Flatten@m ~Partition~ Length@Flatten@First@m ]


2

I'm posting this just to show that in Mathematica, it is entirely possible to start from the definitions: pointTriangleDistance3D[pt_?VectorQ, tri_?MatrixQ] := Module[{p1 = First[tri], s, t}, Sqrt[MinValue[{SquaredEuclideanDistance[pt, p1 + {s, t}.Map[# - p1 &, Rest[tri]]], 0 <= s <= 1, 0 <= t <= 1, s + t <= 1}, {s, ...


2

Seems no holdon, but to achive the same effect is easy too. Add a Joined->True, looks like a joined curve now Clear["`*"]; forward[{x1_,y1_},{x2_,y2_},v_: 5]:=Block[{alpha},alpha=Switch[Sign[x1-x2],-1,ArcTan[(y2-y1)/(x2-x1)],1,Pi+ArcTan[(y2-y1)/(x2-x1)],0,Pi/2,_,-Pi/2];{x1+v 0.01 Cos[alpha],y1+v 0.01 Sin[alpha]}]; list={}; ...


1

I think you can only export data in the form of matrices in version 7. If you want to store multiple pieces of data x and y, you can do something like this: x = {1, 2, 3}; y = {4, 5, 6, 7, 8}; z = PadRight[{x, y}]; Export["testz.mat", z] In Matlab, you will have one thing, called "Expression1" that consists of the matrix z. You will have to unpack it ...



Only top voted, non community-wiki answers of a minimum length are eligible