Search code examples
matlabuser-interfacewolfram-mathematicalinear-algebra

Export function from mathematica to matlab


Im trying to export a function that draws a heart from mathematica...

Export[NotebookDirectory[] <> "anim1.gif", Table[
   Plot[Sqrt[Cos[x]]*Cos[200*x] + Sqrt[Abs[x]] - 0.7*(4 - x*x)^0.01,
   {x, -2, t}, PlotStyle -> Red, Frame -> True,
   Axes -> False, PlotRange -> {{-2, 2}, {-1.7, 1.1}}]
, {t, -1.57, 2, 0.01}]]

enter image description here

...to matlab. But I dont know how instead of making a gif a would like to draw the image in a single step, to apply some processes later over the image.

I have trying to make a symbolic variable with

>> sim x

But when entering the function that try to plot

plot([Sqrt[Cos[x]]*Cos[200*x] + Sqrt[Abs[x]] - 0.7*(4 - x*x)^0.01,))

it always says.

Error: Unbalanced or unexpected parenthesis or bracket.

Update
I have managed to plot it as

x = [-2:0.000001:2];
>> plot ((sqrt(cos(x).*cos(200*x))+sqrt(abs(x)))-(0.7*(4-x.^2).^(0.01)))

But still gives me the next incomplete image

enter image description here


Solution

  • Defining a time vector

    x=[-2:.001:2];
    

    Writing the function

     y=(sqrt(cos(x)).*cos(200*x)+sqrt(abs(x))-0.7).*(4-x.*x).^0.01;
    

    ploting it

     plot(x,y)
    
    Warning: Imaginary parts of complex X and/or Y arguments ignored
    

    enter image description here