Can you store symbolic functions in a matrix/vector?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
KieranSQ
am 4 Feb. 2019
Kommentiert: Walter Roberson
am 6 Sep. 2020
I am trying to write a finite element code. I want to consider the basis functions
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202666/image.png)
So I need to be able to store them in a matrix/vector such as:
. In matlab I tried the following ,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202667/image.png)
phi=@(x,y)1/h.*[1-x-y;x;y]
but I either get an error for variables not being defined (which is the point at this stage). From here I want to do something like the following, but I can't see how. Any help would be appreciated!
phi(1)=1/h[1-x-y]
1 Kommentar
Akzeptierte Antwort
Walter Roberson
am 4 Feb. 2019
Symbolic functions cannot be stored in a regular vector or array. If you concatenate symbolic functions, then what you get back is not a vector of symbolic functions but rather a single symbolic function that returns a vector. This is because the () indexing operation for symbolic functions is always interpreted as invocation of the function, never as indexing.
This is also part of the same reason that function handles cannot be stored in a regular vector or array, because () for function handles always means invocation, never indexing.
You can store symbolic functions as elements of a cell array.
Symbolic expressions can be stored in a vector or array. Most of the time it is easier to work with symbolic expressions rather than symbolic functions. However if you need to express differentiation of a symbolic function whose definition is not fully known, such as a differential equation, then you need a symbolic function.
0 Kommentare
Weitere Antworten (1)
Sebastian Pakula
am 6 Sep. 2020
There is a way of picking one of the function from matrix (or vector) of functions. Try this:
syms x y
h=10;
phi=(1/h)*[1-x-y;x;y];
% if you need second function write:
f2=[0 1 0]*phi;
% if you need third one:
f3=[0 0 1]*phi;
1 Kommentar
Walter Roberson
am 6 Sep. 2020
You do not show any functions, only expressions.
For expressions you can just index directly, phi(2) for example.
You also need to be careful about 0 times infinity, which would normally be nan.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!