Argument to dynamic structure reference must evaluate to a valid field name.
5 views (last 30 days)
Show older comments
I was asked to use fsole to solve a problem but i keep getting this message "Argument to dynamic structure reference must evaluate to a valid field name."
this is my code
function fsolveDemo
% x(1) = theta1, x(2) = theta2
% x0 is a starting guess of theta1 and theta2.
x0 = [0.1,0.1]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
x = fsolve(@myfun,x0,options); % Call solver
plot(x(1),x(2))
end
function F = myfun(x)
t=(0:0.1:4); p1=8; p2=1+t; L1=5; L2=6;
% Rewrite the equation in the form F(x) = 0
F = [((x(1))-atan(p2./p1)+ asin(L2*sin(x(2))/sqrt.(p1.^2+p2.^2)));((x(2))- acos((p1^2+p2.^2-L1^2-L2^2)./(2*L1*L2)))];
end
please tell me whats wrong
[EDITED, Jan, please apply a proper code formatting - thanks]
2 Comments
Jan
on 17 Mar 2015
Please copy the complete error message. It is not efficient to guess, which line causes the error.
Answers (1)
Jan
on 17 Mar 2015
Edited: Jan
on 17 Mar 2015
In
sqrt.(p1.^2+p2.^2)
Matlab assumes, that "sqrt" is a struct and "(p1.^2+p2.^2)" is the field name. Remove the dot after "sqrt".
You can find the source of such problem using the debugger:
dbstop if error
Then run the code again until it stops at the error. Now evaluated the line piece by piece, until you find, which expression fails.
See Also
Categories
Find more on Systems of Nonlinear Equations 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!