Hi everyone,
I can find the partial derivative of a function using syms:
syms x , d
f = ... % a complicated function of x and d
df = diff(f,d)
I would like now to use x and d as variables in a for loop to calculate df for specific values of x and d. How is this possible? Thank you!

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 25 Jun. 2016
Bearbeitet: Azzi Abdelmalek am 25 Jun. 2016

0 Stimmen

syms x d
f = x*sin(d)
df=diff(f,d)
d1=pi
x1=5
out=subs(df,[d x],[d1 x1])

2 Kommentare

Goldy
Goldy am 25 Jun. 2016
great! thank you! well, what if I want to do something like this:
for x=0:0.1:5
for d=0:20
...
end
end
What would I put instead of
d1=pi
x1=5
out=subs(df,[d x],[d1 x1])
?
k=0;
for x1=0:0.1:5
for d1=0:20
k=k+1;
out(k)=subs(df,[d x],[d1 x1])
end
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by