How can I define an array of symbolic functions?

조회 수: 27 (최근 30일)
Sara Linares
Sara Linares 2020년 2월 8일
댓글: Walter Roberson 2022년 4월 26일
I want to make an array a1(t) a2(t)... an(t).
syms a(t)
creates a symbolic parameter 't' and 'a' which is an unknown function of 't'. I want an array of just this. How do I do that? I want to use this array to solve a system of ODEs using dsolve.

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 8일
In MATLAB it not possible to create an array of symbolic functions. If you have even one symbolic function then MATLAB will build a single function that returns an array.
I was looking at this the other day and noticed that diff(a1, x) would produce a function as output but that diff(a1(x), x) would produce an expression. I was wondering whether that made a difference for dsolve purposes and made a mental note to investigate but I did not get around to it yet.
  댓글 수: 5
Akshay Satpute
Akshay Satpute 2022년 4월 26일
i have a function of x
but i have 4 functions of x
and i want to store them like
a = f(x), b = f(x) , c = f(x) ,d =f(x)
these are the functions for 1 st 4 natural frequencies .
and i want to store and use it in for loop so , i ant to store like
delta = [a b c d ];
but i am not able to do that becuse arrays dont alow to store the expressions .
do you have any idea regarding this?
Walter Roberson
Walter Roberson 2022년 4월 26일
You cannot do that with [] for reasons I explained before. Use a cell array instead.

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

추가 답변 (1개)

Victor
Victor 2020년 4월 24일
I think you can do it with for loop end "execute" command and cell array
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 4월 24일
편집: Walter Roberson 2020년 4월 25일
No, that makes f into a vector of expressions, but the user wanted an array of symbolic functions.
Suppose that you had
syms f1(p) f2(p)
f1(p) = sin(p);
f2(p) = cos(p);
f = [f1, f2];
Then if this was an array of functions, then f(1) would be the function f1, symfun(sin(p),p) . But it isn't:
>> f(1)
ans =
[ sin(1), cos(1)]
That did not index, that took the 1 as the input to the functions.
Your suggestion was
syms f1(p) f2(p)
f1(p) = sin(p);
f2(p) = cos(p);
f = [f1(p), f2(p)];
and then
>> f(1)
ans =
sin(p)
At first that looks good, but if you take a closer look, this is the expression sin(p), not a function. The function would output like
>> f1
f1(p) =
sin(p)
Notice that the function form includes the argument p in the = line, but when we used your suggestion it did not say ans(p) = because f(1) is an expression rather than a function.
Sara Linares
Sara Linares 2020년 4월 25일
Thank you very much to both of you! You were really helpful and I really appreciate your time!!

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

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by