How to use an output from on file as input in another file.
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
The given file "enzymeGeneral.m" generates a vector.  " test-modified.m" generates a Jacobian.
How can I use these answers and sum them up as follows:
and 
Here I try with
function [r,g] = enzymeGeneral(k)
[r]=enzymeLeastSquares(result,grad_all);
[g]=test_modified(result,grad_all);
S=sum(r,8)
V=sum(g,8)
Where "result" is supposed to call for the answer from the respective m. file. 
But this doesn't work, since S and V do not call on the answers from enzymeLeastSquares.m and test_modified.m in order to sum them as given in S and V:
How can I use the answers from enzymeLeastSquares.m and test_modified.m as inputs for S and V in summation?
Thanks
2 Kommentare
  Alexander
      
 am 29 Mär. 2024
				"enzymeGeneral.m" doesn't creat a vector but an error:
>> enzymeGeneral
Unrecognized function or variable 'result'.
Error in enzymeGeneral (line 2)
[r,g]=enzymeLeastSquares(result,grad_all);
Hence, you should rework your scripts.
Antworten (1)
  Alexander
      
 am 30 Mär. 2024
        
      Bearbeitet: Alexander
      
 am 30 Mär. 2024
  
      Do you mean something like this:
function [S,V]=enzymeLeastSquares(r,g);
S=sum(r,8)
V=sum(g,8)
and the calling function might look like this:
function [S,V] = enzymeLeastSquares(k)
N = 4; % number of experiments
result = zeros(2*N,1); % pre-allocate result arrays
grad_all = zeros(2*N,2);
dt=0.01;
T=1;
%k=[5;1];
y0_all = [2 1 1 4; 1 1 0 1];
y1_all = [1.0 0.5 0.3 2.4; 2.1 1.6 0.9 2.7];
for ii = 1:N
    y0 = y0_all(:,ii);
    y1 = y1_all(:,ii);
    [SP,grad]=enzyme(y0,k,dt,T);
    result((ii-1)*2+[1 2]) = y1-SP;
    grad_all((ii-1)*2+[1 2],:) = -grad;
end
[S,V] = enzymeGeneral(grad_all, result)
But I haven't tested this jet. It shows only how to pass prameters onto a function and get results back.
4 Kommentare
  Alexander
      
 am 31 Mär. 2024
				Maybe this:
function [result,grad_all] = enzymeLeastSquares(k)
N = 4; % number of experiments
result = zeros(2*N,1); % pre-allocate result arrays
grad_all = zeros(2*N,2);
dt=0.01;
T=1;
%k=[5;1];
y0_all = [2 1 1 4; 1 1 0 1];
y1_all = [1.0 0.5 0.3 2.4; 2.1 1.6 0.9 2.7];
for ii = 1:N
    y0 = y0_all(:,ii);
    y1 = y1_all(:,ii);
    [SP,grad]=enzyme(y0,k,dt,T);
    result((ii-1)*2+[1 2]) = y1-SP;
    grad_all((ii-1)*2+[1 2],:) = -grad;
end
result = sum(result);
Siehe auch
Kategorien
				Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!