How to rearrenge function with inputs given?

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 Comments

Can you give more details on what exact help you needed?
That's my function of finding Bending force
where E=200, uk=15 ,kk=25,n=1,L=1
and Pkr is the only one missing
Pkr=pi^2*E*1000*(uk*kk^3/12)*n/(L*10^3)^2;
-----------------------------------
And that's my function of finding young's modulus
where Pkr=15, uk=15 ,kk=25,n=1,L=1
and E's the only one missing
E=(pi^2*1000*(uk*kk^3/12)*n/(L*10^3)^2/Pkr)^-1;
I want to find the input which is missing(without any exceptions)
I don't want to write down the function for n variable again and don't want
s=input('what's missing')
if(s=='n')
function result=nfinder
inputdlg(variables etc.)
n=equation just for n
end
else if(s=='pkr)
function result=pkrfinder
inputdlg(variables etc.)
pkr=equation just for pkr
end
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.

Sign in to comment.

Answers (1)

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.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Release

R2021a

Asked:

on 6 Jul 2021

Answered:

on 6 Jul 2021

Community Treasure Hunt

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

Start Hunting!