Clear Filters
Clear Filters

matlab script for f, df and d2f using excel

2 views (last 30 days)
Niels
Niels on 25 Jun 2013
Hello
I'm a biologystudent trying to write some code. What I wanted to do is taking a function (i've choosen the simple f=a.*t.^3+b.*t.^2+c.*t+d but the original formula is more complex). Next I wanted to derive the first and second derivative (step1). Here the outcome seems like expected.
For step2 an excel table test0 with the values for a,b,c and d was uploaded. Every row has different values for a,b,c and d and there are 10 rows. If I use the following code I get 10 different f values with the first function has the values for a,b,c and d from the first row. The second function has the values for a,b,c and d from the second row untill the tenth row.
The outcome for f seems as expected. However df and d2f in my outcome just give the values of f again ten times.
Can Anyone point out where in my code I made a mistake?
Thanks
My code: ----------------------------------------------------------------------
step1: analytical deriving f, df and d2f
t=sym('t');
a=sym('a');
b=sym('b');
c=sym('c');
d=sym('d');
f=a.*t.^3+b.*t.^2+c.*t+d
df=diff(f,t,1)
d2f=diff(f,t,2)
step2: import excelfile to replace variables
ar=xlsread('test0','A:A');
br=xlsread('test0','B:B');
cr=xlsread('test0','C:C');
dr=xlsread('test0','D:D');
f=subs(f,{a,b,c,d},{ar,br,cr,dr})
df=subs(f,{a,b,c,d},{ar,br,cr,dr})
d2f=subs(f,{a,b,c,d},{ar,br,cr,dr})

Answers (0)

Categories

Find more on Data Import from MATLAB 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!