How to rearrenge function with inputs given?

1 visualización (últimos 30 días)
Berke Kadir Türker
Berke Kadir Türker el 6 de Jul. de 2021
Respondida: the cyclist el 6 de Jul. de 2021
f=m.a (where we know m=5 and a=10)
let's say we have that function
but we also could've need
a=f/m (where we know F=10 m=2)
or
m=f/a(where we know F=10 a=4)
in another problem.
This means more and more functions for every other variable and also means that much error handling.
I don't know what's the term i need can you help?
  5 comentarios
dpb
dpb el 6 de Jul. de 2021
Well, MATLAB is powerful but it's not prescient...you have to have a way to identify what variables are available and what aren't -- and if some are missing and have to be computed from other relationships, then those will have to have code from which to be able to derive them.
It's just part of developing general code; you can manage to do it without the direct appeal to the user, but to do so will require a defined interface of a given number of inputs in a given order so missing variables can be found or you have to use named parameters if using class definitions rather than procedural code.
Unfortunately, it is true this is a geometric explosion problem of the number of possible combinations and there are some combinations that could have no way to solve them.
The better route is to probably simply put the onus on the calling routine/user to input at least a minimal set and only deal with those rather than try to be absolutely general.
Berke Kadir Türker
Berke Kadir Türker el 6 de Jul. de 2021
@dpb thank you :)

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 6 de Jul. de 2021
Option 1
You could do something that is GUI-driven, where the user enters values into textboxes that you have labeled as
  • acceleration
  • mass
  • energy
  • (etc)
but allow them to leave one box blank. Then you can infer from which box is empty, which formula to use.
Option 2
You could require the user to enter the values as strings, with the units included, e.g.
'65 Joules'
and then infer the quantity from the units, and calculate accordingly.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by