How to generate a 2 dimensional array when using a subs function with symbollic function array
Show older comments
Good day,
I will try to explain what i want to do as plainly as possible.
I have two vectors:
- One vector contains 4 symbollic functions which are a result of linsolve matrix calculation. All functions contain only one variable "omega".
- Below that i have created a second vector of 2001 variables containing a range of "omega" [0:0.01:20].
Now, what i wanted to do is create a [2 2001] matrix containing calculated values for two functions created on the basis of the previous symbollic vector, while also substituting the omega in those symbollic functions in the same step. What i'm certainly doing wrong is that i'm wrongly defining the matrix (i'm getting the array size error). Could you help me with syntax (or probably suggest a more reasonable approach) as i'm having a trouble wrapping my head around this issue by relying only on syntax provided with help pages.
I don't want to define functions directly (like A1, A2 etc.) because i want the code to work for every possible number of defined amplitudes.
Posting a relevant snippet of code below:
%Matrix solver
[C,F] = equationsToMatrix(Eqn,vars)
%V = vars.'
V = linsolve(C,F) %We are getting a vector of 4 symbollic functions as a result (just specific to this case - could as well be 2 or 6 or more)
syms A
omega = 0:0.01:20; %Omega variable vector definition
%Amplitude calculator
for i=1:length(M) %M is another vector containing masses (its length will always be like "V" divided by 2)
A(i,:) = sym(subs(sqrt(V(2*i-1)^2+V(2*i)^2))); %This is where i'm getting an error, i don't know how to define "A" to properly iterate through both "omega" and "i"
end
1 Comment
Jacek Harazin
on 16 Mar 2023
Answers (1)
Jacek Harazin
on 20 Mar 2023
Categories
Find more on Logical 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!