0

I'm fairly new to matlab and have written the following function to use in the fsolve command.

function F = myfun(x)

F(1)=cos(phi3)+7*cos(x(2))-5*cos(x(5))+7*cos(x(1))-3*cos(phi2);
F(2)=sin(phi3)+7*sin(x(2))-5*sin(x(5))+7*sin(x(1))-3*sin(phi2)+4;
F(3)=2*cos(phi4)-14*cos(x(3))-5*cos(x(6))+7*cos(x(4))-2.5*cos(x(5))+7*cos(x(1))-3*cos(phi2);
F(4)=2*sin(phi4)-14*sin(x(3))-5*sin(x(6))+7*sin(x(4))-2.5*sin(x(5))+7*sin(x(1))-3*sin(phi2)+7;
F(5)=2*cos(phi4)-14*cos(x(3))-5*cos(x(6))+7*cos(x(4))+2.5*cos(x(5))-7*cos(x(2))-cos(phi3);
F(6)=2*sin(phi4)-14*sin(x(3))-5*sin(x(6))+7*sin(x(4))+2.5*sin(x(5))-7*sin(x(2))-sin(phi3)+3;`

For the next part of my problem. I would like to use the derivatives of F(1) to F(6) with respect to x(1), x(2), .. x(6) I would like to write some code e.g. in the command window which could do this job for me and produce the new functions with the derivatives in it. (of course I can easily do it by hand, but it would be a nice implementation)

I have already tried various options with the diff command but can't seem to manage it.

I use this function as x=fsolve(@myfun,[a],options) with a being the initial values for x(1)..x(6) Now I want to generate from F(1)..F(6) new functions G(1)..G(6) which look like G(1)=-sin(phi3)dphi3/dt-7sin(x(2))dx(2)/dt+5sin(x(5))dx(5)/dt... In this equation I will fill in the results from fsolve and then further use them to solve for x(2)/dt (which are angular velocities)

NVH
  • 1
  • 1
  • 1
    To give you the right answer, it would be necessary to understand what you want to do. There are two diff functions [numeric diff, which does not operate on functions but on arrays and takes the difference between elements](http://www.mathworks.com/help/matlab/ref/diff.html) and [the symbolic toolbox one, which roughly differentiates like you would do using pen and paper](http://www.mathworks.com/help/symbolic/diff.html) – Daniel Mar 01 '16 at 16:28
  • Additionally, you seem to be using single values (`x(1)` is just a number?), and one can not differentiate over a constant! – Ander Biguri Mar 01 '16 at 16:31
  • I changed my post. Hope this makes it more clear – NVH Mar 01 '16 at 16:53
  • I think now I understand what you want and I think both symbolic and numeric solutions can be applied here. Can you put the complete code into your question (including the definitions of `options`, `phi1` etc? Do you have the symbolic toolbox available (see `ver` command)? – Daniel Mar 01 '16 at 17:53

0 Answers0