How to use an output from on file as input in another file.

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:
sums up all the vector entries into one scale. Using the output vector of enzymeLesstSquares.m
and
sums up all the jacobian entries acting on each respective vector entry from menzymeLesstSquares.m (usinng the output Jacobian of test-modified.m)
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

"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.
Sergio
Sergio 2024년 3월 30일
편집: Sergio 2024년 3월 30일
@Alexander Thanks for your comment. What you indicate to do is the main question I am asking. How do I take the answer from enzymeLeastSquares.m as a input for enzymeGeneral.m, and the answer of test-modified.m as input for enzymeGeneral.m for that summation operation?

댓글을 달려면 로그인하십시오.

답변 (1개)

Alexander
Alexander 2024년 3월 30일
편집: Alexander 2024년 3월 30일

1 개 추천

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

I run you functions with k = [1 2]. I don't know if these parameters make sense, but your functions finished w/o error. No clue, whether the result is that what you want, but this is another task.
k = [1 2];
[result,grad_all] = enzymeLeastSquares(k)
Sergio
Sergio 2024년 3월 31일
편집: Sergio 2024년 3월 31일
@Alexander Thanks for trying this. I gave it a thumbs up, but I couldn't get any further.
I think that is partly the answer to the problem, what you wrote.
Let me illustrate exactly what is the problem. If you open all files, and then run test-modified.m and then run enzymeLeastSquares.m you will obtain as ouput of enzymeLeastSquares.m the following answer:
ans =
0.0146
-0.0146
-0.0249
0.0249
0.0524
0.0476
0.0125
-0.0125
What I need to do is to sum these entries together, and obtain:
0.0146 -0.0146 -0.0249+ 0.0249+ 0.0524+ 0.0476+ 0.0125 -0.0125 = 0.1
This should be the only operation done by enzymeGeneral.m, for now.
Is that possible, using your existing code?
Thanks!
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);
Thanks; I got Not enough input arguments.
Error in enzymeGeneral (line 13)
[SP,grad]=enzyme(y0,k,dt,T);
but I will take it further with my Professor.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2024a

질문:

2024년 3월 27일

댓글:

2024년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by