I run a matlab code. I get the plots but do not get the variables in workspace. Somebody please help me to fix this.

1 vue (au cours des 30 derniers jours)
I am running the following matlab code.
function whisker_curvature
clear all
%global t x y
x=[1 1 1 1 1 1 1];
% options=optimset('Display''iter');
function F=solver(x)
%options = odeset('RelTol',1e-8,'AbsTol',[1e-5, 1e-5, 1e-5, 1e-5, 1e-5, 1e-5]);
[t,y] = ode45(@equation,[0, 1], [0 0 0 x(1) x(2) x(3) 0]);%,options); % theta-zero_0 is also OK/
s = length(t);
F = [y(s,1)-14.96, y(s,2)-4.48, y(s,3)- 30];%, u(s,4), u(s,5), u(s,6)]; %at theta(1)=11, we have intersting behavior.
plot(t,y(:,1),'--ro',t,y(:,2),'--bo',t,y(:,3), '--g',t,y(:,4),t,y(:,5), '--b',t,y(:,6), 'go',t,y(:,7), '--r') % ,t,y(:,2),'--bo',t,y(:,3),t,y(:,4),t,y(:,5),t,y(:,6), 'go'
% plot(t,y(:,1),'--ro')
%grid on
function dy = equation(t,y) % t is my \sigma and unknowns (x,y,\theta,F,\theta_{obj},s_{obj},x_u)=(y(1),y(2),y(3),y(4),y(5),y(6),y(7))
L = 20;
dy = zeros(7,1);
I get the plots but do not get the variables value in the workspace window.
I suspect this happens due to the following error message received:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead. > In fsolve (line 298) In whisker_curvature (line 7)
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 1400 (the default value).
Someone please help me to fix this problem.
  5 commentaires
Jan le 26 Oct 2017
I've edited the question and applied the formatting now.
The "clear all" on top of a function is completely meaningless. It deteles all variables of the current workspace, but on top of a function the (local!) workspace is empty at all. In addition clear all removes all functions from the memory, and reloading them from the disk is a waste of time. Simply omit the darn clearing. It does not help.

Connectez-vous pour commenter.

Réponses (2)

Niklas Nylén
Niklas Nylén le 26 Oct 2017
Variables created in a function do not get assigned to the base workspace. To debug the variable values you should add a debug stop in your function. When the debugger is stopped the function you will have access to the function's local variables.

Jan le 26 Oct 2017
The warning tells you, that the default "Trust-region-dogleg" cannot be applied to your problem. You can use optimset to enable a suiting method, e.g. the chosen "Levenberg-Marquardt".
It sounds strange, that fsolve stops with an error, but you still get plots. The message tells you, that the maximum number of function evaluations is exceeded. Either it is a bug in the formula, or the problem does not converge, or you have to increase the number of accepted function evaluations.
  5 commentaires
Jan le 27 Oct 2017
Then let me encourage you to read the documentation of your Matlab versions. In the current version (and the online documentation) the command is called "optimoptions", but in your version it might be "optimset".

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by