Can anyone tell me why this function call : [x, ithist] = broyden(f,x0); within my script says x is undefined? broyden.m is supposed to calculate and output x. Am I supposed to define it in my script, because that doesn't seem right or make sense. An

2 ビュー (過去 30 日間)
Timothy Nsubuga
Timothy Nsubuga 2019 年 7 月 2 日
コメント済み: Geoff Hayes 2020 年 10 月 21 日
%*************************************************************************
%%This script will solve for ys and ts assuming the origin of the sample's
%%coordinate system is at the center of the borehole and so xs = zs = 0
%*************************************************************************
xs = 0.00000;
zs = 0.00000;
%these are locations for transducer 1 - 13 which must be determiend
%properly with the next tests...
xt = [-0.05000;-0.05000;-0.05000;-0.05000;-0.05000;-0.05000;0.00140;0.00150;0.00160];
yt = [ 0.01980; 0.01985;0.00100;0.00120; -0.01980; -0.01985;0.01986;0.01987;0.00130];
zt = [-0.01989;0.01990;-0.02980;0.03980;-0.04980;0.05980;0.06980;-0.07980;-0.08980];
v = 2500;% wave speed in material determined by AST and distance formula
File_names = dir('*.csv'); %attain every waveform in the event folder
%get file for reference transducer, in this case the file that contains transducer 1
% file1 = File_names(3).name;
% plus1 = 1;
numFiles = length(File_names);
incr = 2:5;
% allocate an empty array for 5 transducer combinations for a total of 10
% solutions, 5 for ys and ts each
solutions = zeros(5,2);
%open transducer 1 file, this is the reference transducer
% file = File_names(3).name;
%sort all the files in descending transducer order
list = cell(numFiles,1);
for i = 1:numFiles
list(i) = {File_names(i).name};
end
natOrder = natsort(list);
plus1 = 1;%offset value for transducer 1
file_1 = natOrder(1,1);
file1 = cell2mat(file_1);%transducer 1 is the reference transducer an so will always be used in broyden
%get solutions for ys and ts using 5 transducers with transducer 1
for i = 2:5
hold on
plus = incr(i);%offset second graph for plotting
[~,l1] = graphData(file1,plus1);
ordered_file = natOrder(i,1);
file = cell2mat(ordered_file);
[~,li] = graphData(file,plus);
arrivalt1 = l1*1e-7;
arrivalti = li*1e-7;
%deltat1 is clearly zero
deltati = arrivalti - arrivalt1;
%use 2 transducer equations for transducer 1 and another transducers with a guess to call broyden
x0 =[0.00001;1];
f = @(u) [(sqrt((x(1)- xs)^2 + (y(1) - u(1))^2 + (zt(1) - zs)^2)/v )- (u(2));(sqrt((xt(file)- xs)^2 + (yt(file) - u(1))^2 + (zt(file) - zs)^2)/v) - (u(2) - deltati)];
[x, ithist] = broyden(f,x0);
%place each combo's solutions in the solutions array
solutions(i,1) = x(1);
solutions(i,2) = x(2);
end
  5 件のコメント
Mutale Chewe
Mutale Chewe 2020 年 10 月 17 日
Hello,
I am trying to use the Broyden method on MATLAB R2020a, however, it is not recognising the function. I wanted to find out if there are any other tools you had to download to ensure that this worked on your version of MATLAB?
Geoff Hayes
Geoff Hayes 2020 年 10 月 21 日
Mutale - the broyden function might be something you need to download from the MATLAB File Exchange.

サインインしてコメントする。

回答 (1 件)

dpb
dpb 2019 年 7 月 3 日
x0 =[0.00001;1];
f = @(u) [(sqrt((x(1) - xs)^2 + (y(1) - u(1))^2 + (zt(1) - zs)^2)/v )- (u(2)); ...
(sqrt((xt(file)- xs)^2 + (yt(file) - u(1))^2 + (zt(file)- zs)^2)/v) - (u(2) - deltati)];
[x, ithist] = broyden(f,x0);
Because you defined f in terms of dummy variable u and variables x, xs,xt, y, yt, zt, zs, and deltati all of which are defined when the function handle is created, BUT for x which is undefined but needed to evaluate f
Undoubtedly, this isn't what you really intended, but it's what you've written. We can't tell what the real functional should be but that's what's causing the particular error.
NB: when you create a function handle, it contains the values of all variables in the workspace at the time the function handle is created. Those values are invariant and independent of anything that happens to the variables of the same name after the function handle is created--it will NOT reflect any changes made in those variables. Be certain that's what you intended for the behavior of the function handle.
  1 件のコメント
Mutale Chewe
Mutale Chewe 2020 年 10 月 17 日
Hello,
I am trying to use the Broyden method on MATLAB R2020a, however, it is not recognising the function. I wanted to find out if there are any other tools you had to download to ensure that this worked on your version of MATLAB?

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by