Help with using the solve function given parameters and three equations
Show older comments
Here is my code for an internal rate of return (IRR)
clear
clc
D1=45000;
g1=0.04;
n1=40; %years
D2=-60000;
g2=0.06;
n2=4; %years
D3=-30000;
g3=0.02;
n3=44; %years
syms i
%Benefits: Positive Cash Flows
P1=D1*(((1-(1+g1)^(n1))*(1+i)^-(n1))/(i-g1));
%Costs: Negative Cash Flows
P2=D2*(((1-(1+g2)^(n2))*(1+i)^-(n2))/(i-g2));
%Costs: Opportunity Cost (Lost)
P3=D3*(((1-(1+g3)^(n1))*(1+i)^-(n3))/(i-g3));
i = solve(P1+P2+P3==0,i)
I should be getting an answer that is equal to 7.44%. Instead it is displaying a 42x1 matrix with random numbers. I am trying to get the three equations added together and set equal to zero in order to find i. Please help! I'm sure it's an easy fix.
Accepted Answer
More Answers (1)
Walter Roberson
on 8 Jun 2016
With those powers of n1 and n3 being 40 and 44, it is not surprising that the solution is a polynomial of about that order. All of those values are mathematical solutions to the equations you set out.
Cutting short the explanations: use
syms i positive
2 Comments
Alison Alexsy
on 8 Jun 2016
Walter Roberson
on 9 Jun 2016
Use vpasolve() instead of solve()
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!