index notation symbolic toolbox

example: fi = sym('fi',[1 2]) fi =
[ fi1, fi2]
I want this to be: fi =
[ fi(1), fi(2)]
This in order to use outcome of symbolic manipulation directly in my matlab code.

4 Commenti

Dinant
Dinant il 5 Nov 2013
Nobody?
Dinant
Dinant il 19 Feb 2014
Really? Somebody of the Mathworks?
Dinant, I answered your question and provided you with code that does exactly what you asked for. If it's not, please clarify in your comments what you actually want.
Thanks for the help, but you did not. I have reinitiated my post in hope I can get a workaround for this...

Accedi per commentare.

Risposte (6)

Dinant
Dinant il 4 Nov 2013

0 voti

hmmm, what do you mean with the question mark?

7 Commenti

Is this what you're looking for?
Dinant
Dinant il 4 Nov 2013
that gives: fi =
[ 1, 2]
so no.
Which can then be indexed like this:
fi(1)
fi(2)
Which is what you asked for.
Dinant
Dinant il 4 Nov 2013
No it is not. your suggestion simply outputs 1 if i type fi(1). I know I can index it, but, as mentioned in the original posting, I want the output indexed.
if I type fi, I want the answer to be: fi = [ fi(1), fi(2)], or if I type sin(fi(1) I want the output to be sin(fi(1)) and not sin(fi1).
Dinant, this is what my code does:
clear fi;
fi = sym([1 2]);
sin(fi(1))
It will not return two separate outputs because this is not how MATLAB works. Consider the same question for doubles:
[D(1) D(2)] = [1 2]; %error!
You would need to do this on two lines:
D(1) = 1;
D(2) = 2;
Knowing [1 2] upfront you would want
D = [1 2]
Then
D(1)
Dinant
Dinant il 4 Nov 2013
I appreciate your help.
My question relates to the fact that directly want to use the output of symbolic manipulations in my matlab code that is vectorized. Symbolic output is not. It makes from fi(1) fi1. I do not want that. I want the output to be in terms of fi(1), fi(2), etc.
What release are you using? Because on mine(R2013b) it creates a 1x2 sym
Code:
fi = sym([1 2])
size(fi)
sin(fi(1))
Printed:
fi =
[ 1, 2]
ans =
1 2
ans =
sin(1)

Accedi per commentare.

syms fi
then fi(1) will be fi(1)
Dinant Kistemaker
Dinant Kistemaker il 19 Feb 2019

0 voti

I am still very much looking forward to an answer to my question. It is really annyoing that the printed format is not in vector notation. I want to use the output for some symbolic manipulations in my code and I want to use vector notation.
if I type:
fi = sym ('fi',[1 3]);
x=cos(fi)
>>x =
[ cos(fi1), cos(fi2), cos(fi3)]
I would very much want to have the answer in vector notation like:
x =
[ cos(fi(1)), cos(fi(2)), cos(fi(3))]
Dinant Kistemaker
Dinant Kistemaker il 26 Feb 2020

0 voti

I am so looking forward to an answer to my problem...
Somebody from the Mathworks?

1 Commento

If you want an official MathWorks answer please contact Technical Support directly using the telephone icon in the upper-right corner of this page.
I suspect you will not be able to do what you want with sym or syms. Depending on what "use outcome of symbolic manipulation directly in my matlab[sic] code" means the matlabFunction function may be of use.

Accedi per commentare.

Richiesto:

il 4 Nov 2013

Commentato:

il 26 Feb 2020

Community Treasure Hunt

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

Start Hunting!

Translated by