convert symbols to variables

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!

 Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 25 Jun 2016
Edited: Azzi Abdelmalek on 25 Jun 2016
syms x d
f = x*sin(d)
df=diff(f,d)
d1=pi
x1=5
out=subs(df,[d x],[d1 x1])

2 Comments

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

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!