Solve is not returnig solution - matlab

Hi,
I'm trying to find the vector x=[x1 ; x2 ; x3 ; x4 ; x5] by solving:
Valorantigo(1,1)=3441/(1-0.00302+x1) + 3441/(1-0.00261+x1)^2 + 301720.5/(1-0.00208+x1)^3
Valorantigo(2,1)=68750/(1-0.00302+x2) + 1068750/(1-0.00261+x2)^2 + 0/(1-0.00208+x2)^3
Valorantigo(3,1)=170040/(1-0.00302+x3) + 13085020/(1-0.00261+x3)^2 + 0/(1-0.00208+x3)^3
Valorantigo(4,1)=229350/(1-0.00302+x4) + 229350/(1-0.00261+x4)^2 + 5729350/(1-0.00208+x4)^3
Valorantigo(5,1)=34194000/(1-0.00302+x5) + 0/(1-0.00261+x5)^2 + 0/(1-0.00208+x5)^3
My code is:
A=[99.23;100.05;91;107.71;104.1];
B=[3441 3441 301720.5;68750 1068750 0;170040 13085020 0;229350 229350 5729350;34194000 0 0];
N=[300000;1000000;13000000;5500000;32800000];
E=[-0.00302;-0.00261;-0.00208];
[c3,r3]=size(A);
[c4,r4]=size(B);
Valorantigo(1:c3,1)=A(1:c3,1).* N(1:c3,1) ./100;
x=sym ('x',[1 c3]);
x=transpose(x);
for i=1:c3
Valor(i,1)=symfun(0,x);
for j=1:r4
Valor(i,1)=symfun((Valor(i,1)/(1+E(j,1)+x(i,1))^j)+((B(i,j)/((1+E(j,1)+x(i,1))^j))),x);
end
end
eqn=Valor(1:c3,1)==Valorantigo(1:c3,1);
[x1,x2,x3,x4, x5, param, cond] = solve(eqn, x, 'ReturnConditions', true);
But the solve don't return any value, can you understand why?

1 Kommentar

Jan
Jan am 19 Jul. 2017
The more threads you open for a specific question, the higher is the level of confusion for the ones, who want to assist you.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Torsten
Torsten am 17 Jul. 2017

1 Stimme

function main
x0=ones(5,1);
sol=fsolve(@myfun,x0)
function F=myfun(x)
A=[99.23;100.05;91;107.71;104.1];
B=[3441 3441 301720.5;68750 1068750 0;170040 13085020 0;229350 229350 5729350;34194000 0 0];
N=[300000;1000000;13000000;5500000;32800000];
E=[-0.00302;-0.00261;-0.00208];
[c3,r3]=size(A);
[c4,r4]=size(B);
Valorantigo(1:c3)=A(1:c3).*N(1:c3)./100;
for i=1:c3
Valor(i)=0.0;
for j=1:r4
Valor(i)=Valor(i)+B(i,j)/(1+E(j)+x(i)^j);
end
F(i)=Valor(i)-Valorantigo(i);
end
Note that your 5th equation does not have a zero - so you will have to exclude it from the above calculation.
Best wishes
Torsten.

6 Kommentare

Mariana Ferreira
Mariana Ferreira am 17 Jul. 2017
Thanks. Could u explain better that about the 5th equation? I'm not understanding.
John D'Errico
John D'Errico am 17 Jul. 2017
Bearbeitet: John D'Errico am 17 Jul. 2017
Valorantigo(5,1)=34194000/(1-0.00302+x5) + 0/(1-0.00261+x5)^2 + 0/(1-0.00208+x5)^3
But see that TWO of the terms are zero ALWAYS. They are 0/stuff. So the 5th equation reduces to trying to solve for x5, such that
34194000/(1-0.00302+x5) == 0
Under what circumstances with that EVER be zero? NONE. There is no real or complex value for x5 that makes the left hand side zero.
But
Valorantigo(5,1)==34144800
so it will be
34194000/(1-0.00302+x5) == 34144800
Torsten
Torsten am 18 Jul. 2017
You are right.
Best wishes
Torsten.
Mariana Ferreira
Mariana Ferreira am 18 Jul. 2017
Now that I checked the solution obtained is not right, for the first should be 1,4299, for the second 7,1098 and so on. I tried to include optimset but didnt work.
Torsten
Torsten am 19 Jul. 2017
Bearbeitet: Torsten am 19 Jul. 2017
If you insert the above values in the first and second equation, you will see that they don't solve them.
But - as Jan pointed out - there is an error in the code: a parenthesis is set incorrectly.
Use
Valor(i)=Valor(i)+B(i,j)/(1+E(j)+x(i))^j;
instead of
Valor(i)=Valor(i)+B(i,j)/(1+E(j)+x(i)^j);
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 17 Jul. 2017

Kommentiert:

Jan
am 19 Jul. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by