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

Can you give more details on what exact help you needed?
Berke Kadir Türker
Berke Kadir Türker 2021년 7월 6일
편집: Berke Kadir Türker 2021년 7월 6일
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
@Soniya Jain tagging you if not notified :)
dpb
dpb 2021년 7월 6일
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.
@dpb thank you :)

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2021년 7월 6일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 7월 6일

답변:

2021년 7월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by