MATLAB GUI derivative calculator

Click For Summary

Discussion Overview

The discussion revolves around creating a MATLAB GUI for calculating derivatives of mathematical expressions input by the user. Participants explore the implementation details, including handling user input and converting strings to symbolic expressions.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant describes their approach to creating a MATLAB GUI with specific components for input and output, expressing challenges with processing user input for derivatives.
  • Another participant points out that MATLAB requires explicit multiplication operators in expressions, suggesting that the input "4x" should be written as "4*x".
  • Multiple participants reference the MATLAB documentation on converting strings to symbolic expressions, specifically mentioning the function str2sym.
  • One participant suggests using Mathematica for symbolic computations instead of MATLAB, indicating a preference for different tools based on their intended use.
  • A participant emphasizes the need to convert the input string to a symbolic expression before taking its derivative, mentioning the function sym2str as necessary for this conversion.

Areas of Agreement / Disagreement

Participants generally agree on the need to convert user input into a symbolic expression for derivative calculations. However, there are differing opinions on the best tools for symbolic computation, with some advocating for MATLAB and others suggesting Mathematica.

Contextual Notes

There are unresolved aspects regarding the correct usage of functions for converting strings to symbolic expressions, as well as the handling of user input in the GUI. Participants express varying levels of familiarity with MATLAB and its documentation.

cookiemnstr510510
Messages
162
Reaction score
14
TL;DR
Hello All, I am trying to create a MATLAB Gui that works by taking the derivative of a function and displays the result.
Hello!
Happy Sunday, I am trying to create a MATLAB GUI that can take an input ( i am starting out with just one variable) and take its derivative and display the result. I have attached pictures of what my GUI looks like, and also the code I wrote so far.
Let me also describe my method:
I have added
1 edit text box whose tag line is "FCN"
1 pushbutton whose tag line is "equalPushButton"
1 static text box whose tag line is "first", the static text box is blue in the picture attached.

I am running into some problems and I think I know why, but cannot seem to figure out how to fix it. Here is what I did
I went to the callback of the pushbutton and added:
syms x (I did this because I was thinking I had to define the variable..?)
a=get(handles.FCN,'string') This is getting the value from the edit text box
b=str2num(diff(a));
set(handles.first,'string',num2str(b));

As an example I would like my program to be able to handle "4x" as an input and when you hit the push button spit out "4" in the static text box (without the quotes).

I believe the problem is somehow I am not telling MATLAB that we have numbers and letters being typed into the edit text box...

I am new to MATLAB and it is pretty difficult to me so any help would be appreciated. The simpler the explanation the better for me.

Thank you!
 

Attachments

  • Derivative .pdf
    Derivative .pdf
    65.5 KB · Views: 560
  • Screenshot (8).png
    Screenshot (8).png
    20.1 KB · Views: 725
Physics news on Phys.org
Orodruin said:
https://www.mathworks.com/help/symbolic/str2sym.html
Other than that, you cannot just enter 4x. Matlab will want the multiplication operator.

Also, my suggestion is to use Mathematica for symbolic computations and Matlab for what it was made for.
Okay, I will look over that article right now.
I haven't used Mathmatica. I am currently working on a project for my MATLAB project and I need to be able to take derivatives in my program.
 
Orodruin said:
https://www.mathworks.com/help/symbolic/str2sym.html
Other than that, you cannot just enter 4x. Matlab will want the multiplication operator.

Also, my suggestion is to use Mathematica for symbolic computations and Matlab for what it was made for.
Yeah, unfortunately the documentation that Mathworks has on their site is challenging for me to understand, that's why I'm here asking questions! I assume posting this was supposed to steer me in the right direction of using str2sym somewhere? Would I be using str2sym when I am assigning my "b" variable to be the derivative of my "a" variable (the one the user inputs)?
Thanks
 
Your variable "a" is a string and not a symbolic expression that can be evaluated. In order to turn it into a symbolic expression, you will need to convert it to one using sym2str, which is what that function is for. If you do not do this, you will not be able to take the derivative of it.
 
  • Like
Likes   Reactions: cookiemnstr510510
Orodruin said:
Your variable "a" is a string and not a symbolic expression that can be evaluated. In order to turn it into a symbolic expression, you will need to convert it to one using sym2str, which is what that function is for. If you do not do this, you will not be able to take the derivative of it.
Ahhh, okay! I appreciate it. I will let you know how it goes!
Thanks
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
21K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
16K
  • · Replies 4 ·
Replies
4
Views
18K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
12K
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K