convert code from mathematica to matlab

17 vues (au cours des 30 derniers jours)
david
david le 15 Juin 2023
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 commentaires
chicken vector
chicken vector le 15 Juin 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 le 16 Juin 2023
Tnx,
delta is value,
Id1, Ival= array

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 16 Juin 2023
Modifié(e) : Walter Roberson le 21 Jan 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 commentaire
david
david le 16 Juin 2023
Modifié(e) : david le 16 Juin 2023
Thanks about help.
yes, probably in mathematics this option exists.
i try it's

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by