Plot an UItable and store variable from a loop into an array

2 vues (au cours des 30 derniers jours)
C Ma
C Ma le 23 Nov 2014
Commenté : C Ma le 25 Nov 2014
Hello everyone I'm very new to Matlab and i just found this useful code to solve non linear systems with Newton-Rapshon method. i'm just trying to modify it in order to iterate the process with a series of values (and I've done that with a for loop that works great) and display them in a simple table of rows and colums. My problem is how to store the values into an array that would be used in the string of the UItable, otherwise my table would be filled up with just the last value of iteration... I'm gonna post the code below and I'll give you the link of the page of mathworks where I found the original code. Thank you in advance for the help.
P.S. Sorry for my english
if true
% %% Solver of non linear systems:
%
% this routine solves a nonlinear system with the Newton-Raphson
% iterative method
%
% The following steps are followed:
%
% 1)Reading of the parameters of the solution:
%
% -max number of iterations: max_iter
% -maximum variation to define convergence criteria: epsilon
% -number of equations in the non-linear system: Nsys
%
% 2)Reading of the equations
%
% -Reading of the equations of the non-linear system
% -Reading of the initial condition vector
% -Verification of the input data in order to detect incorrect inputs
%
% 3)Iterative calculation (repeated until convergence):
% 3.1)Assemblage of the matrix of derivate functions
% 3.2)Calculate the new value of the variables (given by this
% iteration)
% 3.3)Compare the difference between the new and old values with the
% converging criteria (epsilon)
%
% 4)Presentation and store of the result values
%
%
for i = 0:5:360
%%%%%1 Reading of the parameters of the solution:
array2 = [0:5:360];
%maximum number of iterations
maxiter=1000;
%parameter to establish the convergenvce criteria
epsilon=0.0000000001;
%number of equations in the non-linear system to solve
nsys=2;
%% %%%%% 2)Reading of the (nsys)equations
%Standard form of definition of the equations: % %F1 = @(x1,x2,x3) x1+x2-x3+b*a; % % *The equations are defined as an anonymous function; % *They must be numbered sequentially: F1,F2,F3,... ,Fnsys; % *The function array must be filled with all the F(nsys) functions of % the system: F={F1,F2,F3,... F(nsys)} % *Variables must be numbered like: x1,x2,x3,... ,xnsys; % *Number of equations must be equal to the number of variables and % equal to (nsys) % %Equation 1: (F1) F1 = @(x) (-x(1)-0.65)+0.20*cosd(i)+0.45*cosd(x(2)); %Equation 2: (F2)
a=5;
F2 = @(x) +0.20*sind(i)+0.45*sind(x(2)); %%%%% Function array
F={F1,F2};
%%%%% Reading of the initial condition of all the (nsys) variables
nls_aleatory_initial_values;
%The values could instead be inputed one by one like done bellow: %x(1)=1 %x(2)=4 %x(3)=6
%%%%% Verification of the input data:
%(to be created)
%Function array has an order equivalent to nsys
%(to be created)
%% %%%%% 3)Iterative calculations
nloop=0; nconverg=0;
while nloop<maxiter
%%%%%Assemblage of the matrix of derivative functions
dFidxj=zeros(nsys,nsys);
for i=1:1:nsys
for j=1:1:nsys
nls_derivada;
end
end
%% %%%%% Calculation of the vector with the values of each function
for i=1:1:nsys
j=F{i};
D(i,1)=j(x);
end
%%%%%Calculation of the error
A=inv(dFidxj);
error=A*D;
dx=error';
%% %%%%% Adding the error to the x to obtain the new iteration
x=x-dx;
%% %%%%% Parameter to determine the end of the while loop
%%%%While loop counter
nloop=nloop+1;
nconverg=nconverg+1;
%%%%Converging criteria (error < epsilon)
maxdx=max(abs(error));
if maxdx<epsilon
nloop=maxiter;
end
end %% %%%%% 4)Presentation and store of the result value %%% The values of the variables x(1), x(2),... x(nsys) can now be atributed %%% to their respective destines
end f = figure('Position',[440 500 461 146]);
% create the data d = [i x(1) x(2)]; % Create the column and row names in cell arrays cnames = {'phi2', 'phi3','s'}; rnames = {0:5:360};
% Create the uitable t = uitable(f,'Data',d,... 'ColumnName',cnames,... 'RowName',rnames); end
  2 commentaires
Image Analyst
Image Analyst le 23 Nov 2014
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup, or better yet, just attach the code with the paperclip since it's kind of long.
C Ma
C Ma le 25 Nov 2014
here is the link, provided directly from Mathworks:
P.S. thank you for your answer

Connectez-vous pour commenter.

Réponses (1)

C Ma
C Ma le 23 Nov 2014
I'll repost it if someone teaches me how to insert the cod correctly...

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by