How to write a vector-valued function with vector input from the screen in MATLAB?
Show older comments
I am trying to do the following in MATLAB:
1. input *from screen* a small positive integer M (between 1 and 8);
2. input *from screen* M function expressions with variables `t, x1, x2, ... xM`; name for now these M functions f1,f2,...,fM;
3. given a vector `v=[t,x1,x2,...,xM]`, evaluate each of the M functions with the input `v`;
4. the output is a vector `Y=[y1,y2,...,yM]` where `y1=f1(v),y2=f2(v),...`.
I learned from this [old code][1] that I can do (1) and (2) with
TRUE = 1;
FALSE = 0;
OK = FALSE;
while OK == FALSE
fprintf(1,'Input the number of equations\n');
M = input(' ');
if M <= 0 | M > 7
fprintf(1,'Number must be a positive integer < 8\n');
else
OK = TRUE;
end;
end;
ss = cell(M,1);
for I = 1:M
fprintf(1,'Input the function F_(%d) in terms of t and y1 ... y%d\n', I,M);
fprintf(1,'For example: ''y1-t^2+1'' \n');
kk = input(' ');
ss{I} = kk;
end;
How can I do (3) and (4)?
[1]: https://www.mathworks.com/matlabcentral/answers/uploaded_files/97690/ALG057.m
Accepted Answer
More Answers (0)
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!