Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8673429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:27:24+00:00 2026-06-12T19:27:24+00:00

I am trying to differentiate the following symbolic expression using a created symbolic vector

  • 0

I am trying to differentiate the following symbolic expression using a created symbolic vector but I keep getting errors. That is, I would like df/dx1, df/dx2, and df/dx3. Here is what I have tried:

>> x = sym('x', [3 1])

x =

 x1
 x2
 x3

>> symbolic = 0.5*transpose(x)*eye(1)*x + [1 1 1]*x

symbolic =

x1^2/2 + x1 + x2^2/2 + x2 + x3^2/2 + x3

>> diff(symbolic, x)
Error using mupadmex
Error in MuPAD command: Invalid argument. [contains]

  Evaluating: (Dom::Matrix(Dom::ExpressionField()))::_mult1

Error in sym/diff (line 44)
    R = mupadmex('symobj::diff', S.s, x.s, int2str(n));

>> diff(symbolic, x.x1)
Error using sym/subsref
Too many output arguments.

Any assistance would be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:27:25+00:00Added an answer on June 12, 2026 at 7:27 pm

    You can try one of these two options:

    % option 1
    x = sym('x', [3 1]);
    f = 0.5*transpose(x)*eye(1)*x + [1 1 1]*x;
    
    for i=1:3
        Df(1,i) = diff(f, x(i));
    end
    
    % I do not like this option because I do not know 
    % how to evaluate the expressions with numeric values
    x(1) = 1;
    eval(Df)
    

    I prefer the ‘option 2’, because it is easier to evaluate expressions.

    % option 2
    syms x1 x2 x3 real; % 'real' fixes x1 x2 x3 as real numbers (not complex ones)
    x = [x1 x2 x3]'; % '
    f = 0.5*transpose(x)*eye(1)*x + [1 1 1]*x;
    
    for i=1:3
        eval(['Df(1,i) = diff(f,x',num2str(i),');']);
    end
    
    % To eval at a certain value
    x1 = 1;
    x2 = 2;
    x3 = 3;
    eval(Df)
    

    I think that eval has only the two functions I used above:

    1. To eval symbolic expressions to specific values of the symbolic variables, like when I wrote eval(Df).
    2. You can use eval to evaluate a matlab command written as a string, as if you were writing it as normal code. Try this to see what I mean:

      a = 1; % set value of a to 1

      eval(‘a = 2’); % change value of a to 2

      eval([‘a = ‘,num2str(5)]); % set value of a to 5;

    Hope this helps,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to achieve the following, in php i have a form like this:
I'm trying to create a tabbed sidebar with sections, like the following in WPF.
I'm trying to create a form_for using the following fields. However, some of the
I am trying to create a rpm package using ant task for that I
I am trying to differentiate a click from a swipe in Javascript using touch
I am trying to create a Socket Hello World program. I would ideally like
I'm trying to differentiate between a disclose arrow being 'On' (pointed down) or 'Off'
I have been looking at trying to differentiate between editing states in my UITableView.
I am trying to come up with a method to differentiate between form being
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.