Matlab questions from newbies.

3 Ansichten (letzte 30 Tage)
Eugene
Eugene am 4 Okt. 2014
Beantwortet: John D'Errico am 4 Okt. 2014
R = 8.31453Jmol-1K-1 in matlab command is it R=8.31453.*J.*(mol^-1).*(K^-1)? Do we need to use the .* in such case?
T = 273.15K means T=273.15*K Am i right?

Akzeptierte Antwort

Mischa Kim
Mischa Kim am 4 Okt. 2014
Bearbeitet: Mischa Kim am 4 Okt. 2014
Eugene, MATLAB does not know about units and only takes care of the numerics. In other words, you need to make sure that the units in an equation are compatible. E.g., looking at Newton's 2nd law of motion, F = ma: if you are using SI units, mass is given in kg, acceleration in m/s^2, and force in N. If, for example, acceleration is given in cm/s^2 you need to make the conversion (to m/s^2). MATLAB only keeps track of the numeric values of m, a, and F. So in your case (ideal gas law?):
R = 8.31453;
T = 273.15;
  1 Kommentar
Eugene
Eugene am 4 Okt. 2014
Yes i understand what u mean. Thanks you for your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

per isakson
per isakson am 4 Okt. 2014

John D'Errico
John D'Errico am 4 Okt. 2014
A number is just a number, no more than that. As Mischa said, there are no units in MATLAB, unless you use a toolbox that provides them for you. (There is at least one units toolbox on the FEX.)
Only you know that this particular number refers to a temperature in degrees K, as opposed to the speed of light when passing through honey, here maybe measured in giga-furlongs per fortnight.
You other question was about a need to use .*, and the simple rule is, for scalar multiplies, it does not matter. Here your terms are all apparently scalars, not vectors or arrays. So .* will be the same as *, nothing to worry about.
Had you have some of those arguments as vectors or arrays, and you wanted to use an element-wise multiply, then you need to use .* as the operator, as well as .^ and ./ if they too were employed.
It is not a bad idea to just get in the habit of always using .* for your multiplies in these things. That way there will be no mistake, and only use * for when you really need a matrix multiply between matrices and/or vectors. But that is purely personal preference.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by