Help with using the solve function given parameters and three equations
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
Walter Roberson
2016-6-8
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
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Solvers 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!