×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Diff () function

Diff () function

Diff () function

(OP)
I am a student, and we have put together a small script to calculate the roots of an equation using newton raphson itteration in Matlab - all well and good. However, I decided it would be nice if you could change the function from the terminal, rather than changing the code each time you wanted to solve a new problem.

The problem is, the way most people will enter an equation is in symbolic notation (e.g x^2 +3). On top of this, I need to differentiate my function, (i.e obtain 2x from the above). The diff function will do this, but only (it seems) if fed a symbolic equation.

However, I need the equation in the form
x.^2 +3 - note the x. for element operations - or else my program fails spectacularly

Is there any way I can convert from symbolic notation to this?

Thanks

Ben   

RE: Diff () function

Hi,
Just convert it to non-symbolic array:
>> X=sym(magic(4))
 
X =                       % symbolic input
 
[ 16,  2,  3, 13]
[  5, 11, 10,  8]
[  9,  7,  6, 12]
[  4, 14, 15,  1]
>> z=double(X)            % get ride of symbolic properties

z =

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

>> d=diff(z.^2-1)

d =

  -231   117    91  -105
    56   -72   -64    80
   -65   147   189  -143
D=sym(d)  % If you need a symbolic result

 
D =
 
[ -231,  117,   91, -105]
[   56,  -72,  -64,   80]
[  -65,  147,  189, -143]

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources