0

I wanted to solve the following equation in MATLAB R2013a using the Symbolic Math Toolbox.

(y/x)-(((1+r)^n)-1)/r=0  where y,x and n>3 are given and r is the dependent variable

I tried myself & coded as follows:

f=solve('(y/x)-(((1+r)^n)-1)/r','r')

but as the solution for r is not exact i.e. it is converging on successive iterations hence MATLAB is giving a warning output with the message

Warning: Explicit solution could not be found.
 f =

[ empty sym ]

How do I code this?

ServerS
  • 452
  • 3
  • 15
  • For general `n` it may be hard to find an explicit symbolic solution to this (Mathmatica can't solve this sort of equation either, by the way). You say that `x`, `y`, and `n` are "given" – does that mean that you have numeric values for them? – horchler Aug 26 '14 at 15:35
  • @horchler value for y=441361, x=66990 & n can be any number more than 3. – Sandeepan Roy Aug 30 '14 at 10:50
  • Is `n` an integer? Is it real-valued or potentially complex? These are all things that need to be made explicit when solving such problems or the solver will make assumptions (possibly the wrong ones) for you. – horchler Aug 30 '14 at 12:13
  • @horchler sorry for not mentioning . n is a an integer. – Sandeepan Roy Aug 31 '14 at 06:39

2 Answers2

0

I think you forgot to define n as well.

     f=solve('(y/x)-(((1+r)^n)-1)/r=0','n-3>0','r','n')

Should solve your problem :)

Iris
  • 41
  • 3
  • Nope, this does not work. It still returns the same warning about not finding any explicit solutions. – horchler Aug 26 '14 at 15:37
  • ok, sorry for that, I tried to reproduce the problem with just some very simple made up values for y and x (1 and 2 I think) and at least for that values I got an output with my code. But sure it depends on your input x and y, whether an explicit solution can be found without fixing n, as you commented above. – Iris Aug 28 '14 at 09:41
  • for y=441361, x=66990, n=5 the code you suggested, gave the following message "Warning: Could not extract individual solutions. Returning a MuPAD set object. > In solve>assignOutputs at 219 In solve at 193 In GMprogram at 59 f = (solvelib::VectorImageSet(matrix([[z], [0]]), z, C_) union solvelib::VectorImageSet(matrix([[(log((x + y*z)/x) + pi*k*(2*i))/log(z + 1)], [z]]), [k, z], [Z_, C_ minus {-1, 0}])) intersect solvelib::VectorImageSet(matrix([[u], [z]]), [u, z], [Dom::Interval(3, Inf), C_]) – Sandeepan Roy Aug 30 '14 at 10:41
0

There are an infinite number of solutions to this for an unspecified value of n > 3 and unknown r. I hope that it's pretty clear why – it's effectively asking for a greater and greater number of roots of (1+r)^n. You can find solutions for fixed values of n, however. Note that as n becomes larger there are more and more solutions and of course some of them are complex. I'm going to assume that you're only interested in real values of r. You can use solve and symbolic math for n = 4, n = 5, and n = 6 (for n = 6, the solution may not be in a convenient form):

y = 441361;
x = 66990;
n = 5;
syms r;
rsol = solve(y/x-((1+r)^n-1)/r==0,r,'IgnoreAnalyticConstraints',true)
double(rsol)

However, the question is "do you need all the solutions or just a particular solution for a given value of n"? If you just need a particular solution, you shouldn't be using symbolic math at all as it's slower and has practical issues like the ones you're experiencing. You can instead just use a numerical approach to find a zero of the equation that is near a specified initial guess. fzero is the standard function for solving this sort of problem in a single variable:

y = 441361;
x = 66990;
n = 5;
f = @(r)y/x-((1+r).^n-1)./r;
r0 = 1;
rsol = fzero(f,r0)

You'll see that the value returned is the same as one of the solutions from the symbolic solution above. If you adjust the initial guess r0 (say r0 = -3), it will return the other solution. When using numeric approaches in cases when there are multiple solutions, if you want specific solutions you'll need to know about the behavior of your function and you'll need to add some clever extra code to choose initial guesses.

horchler
  • 18,384
  • 4
  • 37
  • 73