MATLAB Matlab Difference Equation Loop?

AI Thread Summary
The discussion centers on creating a MATLAB loop to differentiate the function f = @(x) x2√4x+1 from the original function (n=0) to the 5th derivative (n=5) and substituting the value 2 into these derivatives. The user encounters an issue where MATLAB requires the nth term to be a scalar number rather than a variable. The goal is to modify the loop to allow for the differentiation to occur dynamically for each value of n. The user seeks guidance on how to implement this correctly within the MATLAB environment while maintaining the intended functionality of the loop.
Dukefool
Messages
4
Reaction score
0
Trying to make a three line loop that would differentiate x2√4x+1 to the nth term starting from the original function (n=0) to the 5th derivative (n=5) and then substitute 2 into the derivatives. Here's what I got

f = @(x) x2√4x+1
For n=[0:5] - As the nth term goes from 0 to 5
disp(num2str(subs(diff(f(x),n),2)))
end

Matlab says that the nth term must be an actual scalar number instead of a variable. I want the nth term to change so how can I do that?
 
Physics news on Phys.org
Dukefool said:
Trying to make a three line loop that would differentiate x2√4x+1 to the nth term starting from the original function (n=0) to the 5th derivative (n=5) and then substitute 2 into the derivatives. Here's what I got

f = @(x) x2√4x+1
For n=[0:5] - As the nth term goes from 0 to 5
disp(num2str(subs(diff(f(x),n),2)))
end

Matlab says that the nth term must be an actual scalar number instead of a variable. I want the nth term to change so how can I do that?

for n = 0:5
 

Similar threads

Replies
5
Views
3K
Replies
10
Views
3K
Replies
1
Views
2K
Replies
4
Views
1K
Back
Top