Filter löschen
Filter löschen

how to write a formula in matlab?

2 Ansichten (letzte 30 Tage)
Vika
Vika am 16 Sep. 2023
Beantwortet: Walter Roberson am 16 Sep. 2023
  1 Kommentar
Image Analyst
Image Analyst am 16 Sep. 2023
Not sure what you mean. Do you want to write that formula to the command window or onto an axes or image? Or do you have all those variables and want to carry out the operations (like log, squaring, differentiation, etc.)?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Sep. 2023
Use the Symbolic toolbox. Declare symbolic variable names with syms such as
syms h_I T_0 t z
MATLAB has no implicit multiplication at all. For the purpose of this formula, use the .* (dot asterisk) operator for every multiplication.
Use log for ln
In MATLAB, {} has nothing at all to do with grouping or precedence: use () instead of {} for those. You will get errors if you use {}
In MATLAB, [] is for creating vectors and arrays, not for grouping or precedence. Use () instead of [] for those. If you use [] you might get the results you want, but you would have to be careful about the spacing. For example, in MATLAB (A -1) is always "subtract 1 from A" but [A -1] means to try to create a row vector with the elements of A followed by the scalar negative-one. It is best to avoid using [] for grouping or precedence.
In MATLAB, a function name such as log followed by an expression in () is a request to invoke the function on the parameters listed inside the () expression. In MATLAB, a function name such as log followed by an [] expression is typically going to result in a syntax error, but from time to time depending on the exact function and the spacing being used, might simply give you an unexpected result. Do not try to use [] for function parameters in MATLAB.
When using the symbolic toolbox, for differentiation see diff
Note that taking the partial derivative of T_0 with respect to t implies that T_0 is a function of at least one variable. You would need to declare it with syms such as
syms T_0(t, z)
If is intended to represent derivative of s then that implies s is a function, and you would need to declare it, such as
syms s(t)
s_prime = diff(s)

Community Treasure Hunt

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

Start Hunting!

Translated by