Why I cannot run a function for each of the elements of a vector if the function calls the variable two times?
Show older comments
Hello, guys! I am new to Matlab, so take it slowly.
I wrote the following function of the "time" variable:
function A = x1(t)
%Ordinary differential equation solution
% x function of time
X=1;
fn=1;
phi=0;
wn=2*pi*fn;
xi=0.1;
A=X*exp(-xi*wn*t)*cos(sqrt(1-xi^2)*wn*t-phi);
end
And after that I declared the "time" vector:
t=1:0.001:10;
Now, I would like to define a vector with the values of the function for each vector element:
C=x1(t);
But Matlab doesn't like it and says:
Error using *
Inner matrix dimensions must agree.
Error in x1 (line 9) A=X*exp(-xi*wn*t)*cos(sqrt(1-xi^2)*wn*t-phi);
Error in Time (line 2) C=x1(t);
Can you explain me what I am doing wrong? Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Operating on Diagonal Matrices 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!