1

I'm getting these error:

Conversion to function_handle from double is not possible.

Already searched about it and tried to change my code but without sucess. Could u help? Thanks

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);

x=sym ('x',[1 c3]);
x=transpose(x);

for i=1:c3
    Valor(i,1)=0;
    for j=1:r4
        Valor(i,1)=@(x){(Valor(i,1)/((1+E(j,1)+x(j,1))^j))+(B(i,j)/((1+E(j,1)+x(j,1))^j))};
    end
end

What I want is to find the vector x given that I already have a vector Valorantigo that I will use to apply solve.

Valorantigo(1:c3,1)=A(1:c3,1).* N(1:c3,1) ./100;
eqn=Valor(1:c3,1)==Valorantigo(1:c3,1); 
[solx, param, cond] = solve(eqn, x, 'ReturnConditions', true);

Basically x would be the solution of

  • 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
  • the same fot the other lines...
  • what are you triying to acomplish with `=@(x){ .... }` ? just filling the array `Valor`? then just remove that and leave the insides – Ander Biguri Jul 17 '17 at 09:20
  • @AnderBiguri Yes I want to fill the matrix Valor. I put the `{...}` because I saw it as one resolution to my error. Even if I erase that I have the some error. – Arlete Ferreira Jul 17 '17 at 09:27
  • @AnderBiguri already detailed it. Could you help please? I'm working with this since friday and couldnt find a way to fix my code – Arlete Ferreira Jul 17 '17 at 10:48

1 Answers1

0

Just the relevant Part:

 Valor(1,1)=symfun(0,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(j,1))^j+(B(i,j)/((1+E(j,1)+x(j,1))^j)),x);
    end
end

Valor needs to be predefinded as symbolic, with Valor(i,1)=0; you made it to a double.


Oh almost forgot, your solve needs to look like this:

[solx1,solx2,solx3,solx4, solx5, param, cond] = solve(eqn, x, 'ReturnConditions', true);
marco wassmer
  • 421
  • 2
  • 8
  • but that way matlab is not computing the vector _Valor_. Isnt that possible to have a result like this: `Valor=3441/(1-0.00302+x1) + 3441/(1-0.00261+x2)^2 + 301720.5/(1-0.00208+x3)^3`? Thanks – Arlete Ferreira Jul 17 '17 at 09:47
  • @ArleteFerreira made soe changes, works for me now, with your additional code. Alas, I do not know how the solve comand is supposed to work here... – marco wassmer Jul 17 '17 at 11:34
  • why is it creating a 5x3 sym? It should just be a 5x1 sym – Arlete Ferreira Jul 17 '17 at 11:38
  • the code is working but I get this output Empty sym: 0-by-1x1 – Arlete Ferreira Jul 17 '17 at 11:45
  • yes, I can not solve that either. But I suspect it is your equation-system, not Matlab. It my not be solvable. Try it by 'hand', meaning: solve for x1, subsitute into the next equation, then x2, usw. with solve – marco wassmer Jul 17 '17 at 11:59
  • First, my bad, what I want is `Valor(1,1)=3441/(1-0.00302+x1) + 3441/(1-0.00261+x1)^2 + 301720.5/(1-0.00208+x1.)^3` so I altered the code to `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)`. But then if I display Valor(1,1) the result is not right. – Arlete Ferreira Jul 17 '17 at 12:20
  • The result is okay. Thanks a lot for the help :) – Arlete Ferreira Jul 17 '17 at 13:41