convert code from mathematica to matlab

17 visualizaciones (últimos 30 días)
david
david el 15 de Jun. de 2023
Editada: Walter Roberson el 21 de En. de 2025
hello,
need help to convert the folowing code in wolfarm mathematica to matlab,
i try use ToMatlab function, it's nork for me.
the code is:
V1[Ival_] := (volt = Vmax;
While[ Abs[Id1[volt] - Ival] > .005,
Ivolt = Id1[volt];
slope = (Id1[volt] - Id1[volt - \[Delta]])/\[Delta];
volt = volt - (Ivolt - Ival)/slope;
];
volt
Thx
  2 comentarios
chicken vector
chicken vector el 15 de Jun. de 2023
In Matlab you can't have undefined variables like in Wolfram, unless you use symboli toolbox.
If you want to pass your code you have to define them.
What are Id1, Ival and Delta. Are they values, vectors, arrays, functions?
david
david el 16 de Jun. de 2023
Tnx,
delta is value,
Id1, Ival= array

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 16 de Jun. de 2023
Editada: Walter Roberson el 21 de En. de 2025
In Mathematica, that code defines an anonmymous function of one parameter that runs a while loop to do a calculation, and then it assigns the anonymous function to the name V1
MATLAB permits defining anonymous functions, but it makes it difficult to define a while loop inside an anonymous function.
In MATLAB, you would be better off defining a true function using function that accepts parameters of Ival, Vmax, Delta, slope . You might later want to use parameterization http://www.mathworks.com/help/matlab/math/parameterizing-functions.html to specialize the function.
Id1, Ival= array
It has been some time since I used Mathematica heavily; did they eventually add the ability to index arrays at non-integer elements? The code is obviously an implementation of Newton's Method using a numeric approximation of derivative to find a root of function Id1 and it obviously expects scalar Ival and function Id1
In MATLAB, unless you had a specific reason otherwise, you would typically use fzero . ("Specific reason" could include that the function generates complex values.)
  1 comentario
david
david el 16 de Jun. de 2023
Editada: david el 16 de Jun. de 2023
Thanks about help.
yes, probably in mathematics this option exists.
i try it's

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by