Function not using given Variables

1 view (last 30 days)
Sai Sabarish M
Sai Sabarish M on 19 Feb 2019
Commented: Walter Roberson on 20 Feb 2019
I'm trying to solve a system of 6 non linear equations using Newton Raphson Method. I defined my equations with 6 inputs (given as initial guesses) and the function returns value after solving it with the inputs.
Then, while trying to calculate Jacobians,
W=jacobian([f(1),f(2),f(3),f(4),f(5),f(6)],[theta,phi,omega,V,alpha1,beta1]);
Jacobian is evaluated and I get the partial derivatives accordingly.
But when I tried calling a function that calculates Jacobian W, with my initial guess. It does not give me a value, rather the partial derivative itself.
function X=jaccalc(input,W);
theta=input(1)
phi=input(2)
omega=input(3);
V=input(4);
alpha1=input(5);
beta1=input(6);
% other variables were also defined
for i=1:6
X(i)=W(i); %I tried assigning a matrix X in hopes that it would calculate the value with the inputs.
end
end
Kindly help me out. And any advice on making the code efficient is also much appreciated

Answers (1)

Stephen23
Stephen23 on 20 Feb 2019
You will need to use subs:
The loop is superfluous.
  2 Comments
Sai Sabarish M
Sai Sabarish M on 20 Feb 2019
Thank you Stepehen, that did work. But I'm getting values that arent decimals, rather a combination of two huge numbers, when divided gives the numerical value.
-23005294093609302249/14411518807585587200 , (9*pi)/10 - (97*cos(10)^2)/250
Thank you for prompt reply again.
Walter Roberson
Walter Roberson on 20 Feb 2019
That is your jacobian. Decimal would only be an approximation of the jacobian. But if you really want that then double() the answer you are getting .

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!