0

I have a function that is calcualting a profitmargin (PM) given a principal(P).

PMfunction<- function(P,InterestRate,Expenses){
...
There are quite a lot of calcualtions in the middle that come off a table and it's irrelevant
...
return(PM)
}

I now want to calculate the P given a PM so I attempted the below:

uniroot(PMfunction,InterestRate=0.02,Expenses=0.07,lower=0,upper=20000)$root

But this only gives me the value of P such that PM=0. Is there a way I can change the uniroot's defult to find the roots from 0 to my chosen PM?

Andre Wildberg
  • 12,344
  • 3
  • 12
  • 29
Fizboy
  • 1
  • 2
  • 1
    `uniroot` finds where values of functions are equal to 0. If you have a different target in mind, like 5, you can make a different function like `function(...) {5-PMfunction(...}` that would be equal to zero when PMfunction is equal to 5. – MrFlick Apr 19 '23 at 17:19

0 Answers0