Display symbolic formula from string (2024)

Display symbolic formula from string

Since R2019b

collapse all in page

Syntax

displayFormula(symstr)

displayFormula(symstr,old,new)

Description

example

displayFormula(symstr) displays the symbolic formula from the string symstr without evaluating the operations. All workspace variables that are specified in symstr are replaced by their values.

example

displayFormula(symstr,old,new) replaces only the expression or variable old with new. Expressions or variables other than old are not replaced by their values.

Examples

collapse all

Multiplication Formula of Matrix and Scalar

Open Live Script

Create a 3-by-3 matrix. Multiply the matrix by the scalar coefficient K^2.

syms K AA = [-1, 0, 1; 1, 2, 0; 1, 1, 0];B = K^2*A
B =

(-K20K2K22K20K2K20)

The result automatically shows the multiplication being carried out element-wise.

Show the multiplication formula without evaluating the operations by using displayFormula. Input the formula as a string. The variable A in the string is replaced by its values.

displayFormula("F = K^2*A")

F=K2(-101120110)

Multiplication Formula of Matrix and Vector

Open Live Script

Create a 3-by-3 matrix and a 3-by-1 vector. Create a symbolic equation that multiplies the matrix and the vector.

syms A [3 3]syms v B [3 1]eqn = B == A*v
eqn =

(B1=A1,1v1+A1,2v2+A1,3v3B2=A2,1v1+A2,2v2+A2,3v3B3=A3,1v1+A3,2v2+A3,3v3)

The result shows the multiplication being carried out where the elements of the matrix and the vector are combined.

Show the multiplication formula without combining the elements by using displayFormula. Input the formula as a string.

displayFormula("B == A*v")

(B1B2B3)=(A1,1A1,2A1,3A2,1A2,2A2,3A3,1A3,2A3,3)(v1v2v3)

Display Differential Equation

Open Live Script

Define a string that describes a differential equation.

S = "m*diff(y,t,t) == m*g-k*y";

Create a string array that combines the differential equation and additional text. Display the formula along with the text.

symstr = ["'The equation of motion is'"; S;"'where k is the elastic coefficient.'"];displayFormula(symstr)
Theequationofmotionis

m2t2y=mg-ky

wherekistheelasticcoefficient.

Display and Evaluate Symbolic Expression

Open Live Script

Create a string S representing a symbolic expression.

S = "exp(2*pi*i)";

Create another string symstr that contains S.

symstr = "1 + S + S^2 + cos(S)"
symstr = "1 + S + S^2 + cos(S)"

Display symstr as a formula without evaluating the operations by using displayFormula. S in symstr is replaced by its value.

displayFormula(symstr)
1+e2πi+e2πi2+cos(e2πi)

To evaluate the strings S and symstr as symbolic expressions, use str2sym.

S = str2sym(S)
S =1
expr = str2sym(symstr)
expr =S+cos(S)+S2+1

Substitute the variable S with its value by using subs. Evaluate the result in double precision using double.

double(subs(expr))
ans = 3.5403

Display and Solve Quadratic Equation

Open Live Script

Define a string that represents a quadratic formula with the coefficients a, b, and c.

syms a b c ksymstr = "a*x^2 + b*x + c";

Display the quadratic formula, replacing a with k.

displayFormula(symstr,a,k)
kx2+bx+c

Display the quadratic formula again, replacing a, b, and c with 2, 3, and -1, respectively.

displayFormula(symstr,[a b c],[2 3 -1])
2x2+3x-1

To solve the quadratic equation, convert the string into a symbolic expression using str2sym. Use solve to find the zeros of the quadratic equation.

f = str2sym(symstr);sol = solve(f)
sol =

(-b+b2-4ac2a-b-b2-4ac2a)

Use subs to replace a, b, and c in the solution with 2, 3, and -1, respectively.

solValues = subs(sol,[a b c],[2 3 -1])
solValues =

(-174-34174-34)

Input Arguments

collapse all

symstrString representing symbolic formula
character vector | string scalar | cell array of character vectors | string array

String representing a symbolic formula, specified as a character vector, string scalar, cell array of character vectors, or string array.

You can also combine a string that represents a symbolic formula with regular text (enclosed in single quotation marks) as a string array. For an example, see Display Differential Equation.

oldExpression or variable to be replaced
character vector | string scalar | cell array of character vectors | string array | symbolic variable | symbolic function | symbolic expression | symbolic array

Expression or variable to be replaced, specified as a character vector, string scalar, cell array of character vectors, string array, symbolic variable, function, expression, or array.

newNew value
number | character vector | string scalar | cell array of character vectors | string array | symbolic number | symbolic variable | symbolic expression | symbolic array

New value, specified as a number, character vector, string scalar, cell array of character vectors, string array, symbolic number, variable, expression, or array.

Version History

Introduced in R2019b

See Also

str2sym | subs | syms | sym | solve

Comando de MATLAB

Ha hecho clic en un enlace que corresponde a este comando de MATLAB:

 

Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.

Display symbolic formula from string (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Display symbolic formula from string (2024)

References

Top Articles
Best Ethnic Hair Salons Near Me
[PDF] THE MEGACORP SOURCEBOOK - Free Download PDF
My E Chart Elliot
His Lost Lycan Luna Chapter 5
Goodbye Horses: The Many Lives of Q Lazzarus
50 Meowbahh Fun Facts: Net Worth, Age, Birthday, Face Reveal, YouTube Earnings, Girlfriend, Doxxed, Discord, Fanart, TikTok, Instagram, Etc
Craigslist Mexico Cancun
Ub Civil Engineering Flowsheet
Hallowed Sepulchre Instances & More
Produzione mondiale di vino
Ree Marie Centerfold
Lonadine
Breakroom Bw
House Party 2023 Showtimes Near Marcus North Shore Cinema
Studentvue Columbia Heights
Nba Rotogrinders Starting Lineups
WEB.DE Apps zum mailen auf dem SmartPhone, für Ihren Browser und Computer.
Kiddle Encyclopedia
Joann Ally Employee Portal
Forest Biome
EASYfelt Plafondeiland
Evil Dead Rise Showtimes Near Regal Sawgrass & Imax
Titanic Soap2Day
Cincinnati Adult Search
Which Sentence is Punctuated Correctly?
Surplus property Definition: 397 Samples | Law Insider
Tire Plus Hunters Creek
Impact-Messung für bessere Ergebnisse « impact investing magazin
Mjc Financial Aid Phone Number
Remnants of Filth: Yuwu (Novel) Vol. 4
Weather Underground Durham
Shia Prayer Times Houston
United E Gift Card
Does Circle K Sell Elf Bars
2430 Research Parkway
Eero Optimize For Conferencing And Gaming
Clark County Ky Busted Newspaper
About Us | SEIL
Chs.mywork
دانلود سریال خاندان اژدها دیجی موویز
Japanese Big Natural Boobs
Panorama Charter Portal
Lbl A-Z
Autum Catholic Store
Saline Inmate Roster
Jaefeetz
4k Movie, Streaming, Blu-Ray Disc, and Home Theater Product Reviews & News
Unblocked Games - Gun Mayhem
Movie Hax
Ephesians 4 Niv
Craigslist Yard Sales In Murrells Inlet
Syrie Funeral Home Obituary
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 5874

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.