Matlab Difference Equation Loop?

Click For Summary
SUMMARY

The discussion focuses on creating a loop in MATLAB to compute the derivatives of the function f(x) = x^2 * sqrt(4*x + 1) from the 0th to the 5th derivative. The user encounters an error indicating that the nth term must be a scalar number rather than a variable. The solution involves modifying the loop to correctly differentiate and substitute values into the function using MATLAB's symbolic capabilities.

PREREQUISITES
  • MATLAB programming skills
  • Understanding of symbolic differentiation in MATLAB
  • Familiarity with MATLAB's function handles
  • Knowledge of loops and indexing in MATLAB
NEXT STEPS
  • Learn about MATLAB's symbolic toolbox for differentiation
  • Explore the use of function handles in MATLAB
  • Research how to implement loops and conditional statements in MATLAB
  • Study examples of using subs() and diff() functions in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in mathematical modeling, engineering simulations, and anyone looking to enhance their skills in symbolic computation within MATLAB.

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 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K