multiple outputs in symbolic calculation

4 views (last 30 days)
I am trying to calculate the partial derivation of a function over different variables. Then I substitute the value of the variables in order to get a numeric value. The following code lien is used, in this particular case I want to derive a function F respect to a variable m, and x is an array containing the values of the variables:
c1=double(subs(diff(F,m),{m,T1,ratio,I},x))
It works perfectly. However I want to iteratively repeat this computation. Therefore I have created a function that returns c1..c_n where n is the number of variables, the input of the function is the array x.
The idea is to assign the values of a matrix row to the array x and then introduce it in the function.
First I tried to make this step for one single iteration.
However i get a matrix n x m where m is the number of rows in the matrix that contains all the values that i want to evaluate. I dont know what can be due to or even if there is a direct relation between the number of columns of the matrix where i get my array from. Actually the values do not vary so much from one to another, but I would like to have a proper understanding of this behaviour.
For example, I introduce a vector
x= [ 1.2200 -0.5500 0 0.1500 ]
and I get
c1 =
1.1819
1.1775
1.1819
1.1863
1.1863
1.1906
1.1950
1.1601
1.1601
1.1601
1.1688
1.1732
1.1688
1.1819
1.1601
1.1601
1.1688
1.1688
1.1688
1.1644
1.1688
1.1688
1.1732
1.1775
1.1775
1.1470
1.1557
1.1601
1.1644
1.1644
1.1688
1.1688
1.1688
1.1775
1.1688
1.1732
1.1775
1.1775
1.1819
1.1775
1.1688
1.1688
1.1688
1.1775
1.1688
1.1732
1.1732
1.1688
1.1775
1.1732
1.1470
1.1775
1.1819
1.1863
1.1819
1.1819
1.1863
Has somebody experience such a behaviour?

Answers (1)

Walter Roberson
Walter Roberson on 22 Jun 2016
Your F appears to resolve to a vector of length 57. When you subs() into a vector, you get one result for each element of the vector.
  6 Comments
Diego Fraguas Tejero
Diego Fraguas Tejero on 23 Jun 2016
Edited: Diego Fraguas Tejero on 23 Jun 2016
1 1. I just checked that diff() is already returning an output of 57 eq's
And by the way thanks for your attention :)
Walter Roberson
Walter Roberson on 23 Jun 2016
Could you confirm that your F is only length 1 but diff(F,m) is returning a vector of length 57? If so could you check size(m) at that point? If m were a symbolic vector of variable names then the result might not be as expected.
Also, is it possible that although your F is only length 1, that you defined it in terms of variables that were assigned to after they were used to construct F? What is size of subs(F) ?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!