How do I correctly use vpasolve? (2024)

37 views (last 30 days)

Show older comments

Goncalo Costa on 17 Nov 2022

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve

Commented: Walter Roberson on 18 Nov 2022

Open in MATLAB Online

I am trying to numerically solve the following set of equations

M_mag = 1 ; %just some constant simplified here as 1

om = 2*pi*new_freq ; %new_freq is an array of values

C1 = exp(-1i*L.*om./c); % L and c are constant

% phi = exp(1i*om*L/c);

nume = exp(1i.*om.*n*L/c)*4.*n./((1+n).^2); % terms depending on n

denom = 1 + exp(2*1i.*om.*n*L/c).*((n-1)./(n+1)).^2; % terms depending on n

syms n

S = vpasolve(M_mag./C1 == nume./denom , n , guess) %guess is a numerical approach done via another equation, in this case it is 1.7

Whenever I try to use this, I get the following text:

Error using mupadengine/feval_internal

More equations than variables is only supported for polynomial

systems.

Error in sym/vpasolve (line 172)

sol = eng.feval_internal('symobj::vpasolve',eqns,vars,X0);

I have seen similar things being explain in the following link, but I don't understand the explanation. Same for this explanation.

Why can I not solve the equation this way? Is it the exponentials terms?

Thank you very much for your help.

1 Comment

Show -1 older commentsHide -1 older comments

Star Strider on 17 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470213

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470213

I usually use solve, and then vpa the result. It is generally more reliable, especially with functions with multiple roots.

Too much of this code is ‘over the horizon’ and out of sight to provide a specific response.

Sign in to comment.

Sign in to answer this question.

Answers (2)

Torsten on 17 Nov 2022

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#answer_1103048

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#answer_1103048

Edited: Torsten on 17 Nov 2022

You have 2 equations for 1 unknown. MATLAB's symbolic toolbox does not solve such systems.

Is n supposed to be real or complex ?

6 Comments

Show 4 older commentsHide 4 older comments

Goncalo Costa on 17 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470533

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470533

But don't I just have one equation, the one inside the vpasolve function? I separated into parts, but overall it is just one equation, one equality, no?

Or am I missing something (I probably am)? Thanks for your help.

Walter Roberson on 17 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470553

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470553

Open in MATLAB Online

Any one call to vpasolve() or solve() is a call to solve simultaneous equations.

syms x

vpasolve( [4*x+5==9, 3*x - 7 == 2] )

does not try to independently solve [4*x+5==0] and [3*x-7==2]: it tries to find a single combination of values of the variables that solves all of the equations at the same time. You would not expect vpasolve( [4*x+5*y==9, 3*x - 7*y == 2] ) to produce independent solutions for each of the equations, and the action of solve() and vpasolve() for multiple equations does not change just because the multiple equations only have a single variable between them.

Your comments say "new_freq is an array of values" so if you work through, M_mag./C1 == nume./denom is an array of equations. A single solve() call would try to find a single x that solves all of the equations at the same time. A single vpasolve() call will simply refuse to handle the situation (except for polynomials)

So you need to ask vpasolve() to solve each of the equations one-by-one . Which is what my arrayfun() Answer does.

Torsten on 17 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470738

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470738

@Walter Roberson

You'll only get an answer if n can be complex-valued (which I doubt the OP aims at).

Torsten on 17 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470743

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2470743

Edited: Torsten on 17 Nov 2022

Open in MATLAB Online

@Goncalo Costa

Implicitly, you have the equations

real(M_mag./C1 - nume./denom) == 0

and

imag(M_mag./C1 - nume./denom) == 0

And you have a symbolic variable n.

Whether you get a solution that fits your needs depends on whether you accept a complex-valued n or not.

Goncalo Costa on 18 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2471283

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2471283

n is a complex number. Can I change my code for a complex result?

Thank you very much for your help.

Goncalo Costa on 18 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2471293

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2471293

@Walter Roberson that makes sense, I thought that it would solve one-by-one. I didn't understand the limitations of this tool. How can I go around this to have this equation solved for an array? Would a for loop be needed?

Sign in to comment.

Walter Roberson on 17 Nov 2022

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#answer_1103103

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#answer_1103103

Open in MATLAB Online

M_mag = 1 ; %just some constant simplified here as 1

om = 2*pi*new_freq ; %new_freq is an array of values

C1 = exp(-1i*L.*om./c); % L and c are constant

% phi = exp(1i*om*L/c);

syms n

nume = exp(1i.*om.*n*L/c)*4.*n./((1+n).^2); % terms depending on n

denom = 1 + exp(2*1i.*om.*n*L/c).*((n-1)./(n+1)).^2; % terms depending on n

S = arrayfun(@(EQN) vpasolve(EQN,n,guess), M_mag./C1 == nume./denom)

2 Comments

Show NoneHide None

Goncalo Costa on 18 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2471373

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2471373

Dear @Walter Roberson, I have never understood how arrafun works, but it seems to be giving me the right answer. Have you got any link that explain the function written above?

Thank you for your help.

PS: For some reason, the first cell in the cell array separates the complex from the real part of the number.But that can be easily sorted.

Walter Roberson on 18 Nov 2022

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2472973

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/1854258-how-do-i-correctly-use-vpasolve#comment_2472973

Open in MATLAB Online

result = arrayfun(FUNCTION, ARRAY)

is effectively the same as

if isempty(ARRAY)

result = [];

else

out1 = FUNCTION(ARRAY(1));

result = zeros(size(ARRAY), class(out1));

result(1) = out1;

for K = 2 : numel(ARRAY)

result(K) = FUNCTION(ARRAY(K));

end

end

and

result = arrayfun(FUNCTION, ARRAY, 'uniform', 0)

is effectively the same as

result = cell(size(ARRAY));

for K = 1 : numel(ARRAY)

result{K} = FUNCTION(ARRAY(K));

end

and

result = arrayfun(FUNCTION, ARRAY1, ARRAY2)

is effectively the same as

assert(isequal(size(ARRAY1), size(ARRAY2)), 'input arrays must be the same size');

if isempty(ARRAY1)

result = [];

else

out1 = FUNCTION(ARRAY1(1), ARRAY2(1));

result = zeros(size(ARRAY1), class(out1));

result(1) = out1;

for K = 2 : numel(ARRAY1)

result(K) = FUNCTION(ARRAY1(K), ARRAY2(K));

end

end

So you input a function handle (typically), and one or more arrays that must be exactly the same size. The output is the same size as the array. When 'uniform', 0 is specified, the output is a cell array containing the result of executing the function on each corresponding sets of values from the array in turn. If 'uniform', 0 is not specified, the output is a regular array containing the result of executing the function on each corresponding set of values from the array in turn.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABLanguage FundamentalsLoops and Conditional Statements

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

  • vpasolve
  • solve
  • function
  • numerical

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How do I correctly use vpasolve? (13)

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)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How do I correctly use vpasolve? (2024)

FAQs

How does vpasolve work in MATLAB? ›

For polynomial equations, vpasolve returns all solutions. For nonpolynomial equations, there is no general method of finding all solutions and vpasolve returns only one solution by default. To find several different solutions for nonpolynomial, you can set 'Random' to true and use vpasolve repeatedly.

What is the difference between solve and Vpasolve? ›

solve solves equations and inequalities that contain parameters. vpasolve does not solve inequalities, nor does it solve equations that contain parameters. solve can return parameterized solutions. vpasolve does not return parameterized solutions.

How do you solve equations step by step? ›

The following steps provide a good method to use when solving linear equations.
  1. Simplify each side of the equation by removing parentheses and combining like terms.
  2. Use addition or subtraction to isolate the variable term on one side of the equation.
  3. Use multiplication or division to solve for the variable.

How to solve variable equations? ›

These are the general steps for solving an equation with variables:
  1. Step 1: Simplify both sides of the equation.
  2. Step 2: Move all of the parts containing the variable you are solving for to the same side of the equation.
  3. Step 3: Isolate the variable using inverse operations.
Dec 26, 2023

What is the precision of Vpasolve in MATLAB? ›

By default, vpasolve returns solutions to a precision of 32 significant figures. Use digits to increase the precision to 64 significant figures.

How to get MATLAB to solve an equation? ›

S = solve( eqn , var ) solves the equation eqn for the variable var . If you do not specify var , the symvar function determines the variable to solve for. For example, solve(x + 1 == 2, x) solves the equation x + 1 = 2 for x.

What are the best ode solvers MATLAB? ›

ode45 performs well with most ODE problems and should generally be your first choice of solver. However, ode23 , ode78 , ode89 and ode113 can be more efficient than ode45 for problems with looser or tighter accuracy requirements. Some ODE problems exhibit stiffness, or difficulty in evaluation.

What is the difference between resolver and solver? ›

Hi Martina To solve is to find an answer to, explanation for, or means of effectively dealing with (a problem or mystery). To resolve is to settle or find a solution to (a problem or contentious matter) OR to decide firmly on a course of action. Thank you very much for your quick and helpful answer!

What is the difference between self correction and VCP? ›

Compared to the Self-Correction Program (SCP), reasons to use VCP include: Some failures are not eligible for SCP. Sponsors may prefer a written IRS approval even to correct failures that are eligible for SCP. Certain federal income and excise tax relief is available under VCP but not under the SCP.

What are the 3 methods for solving equations? ›

So, in order to solve that problem, you need to be able to find the value of all the variables in each equation. There are three different ways that you could do this: the substitution method, elimination method, and using an augmented matrix.

What are the 4 rules of solving one step equations? ›

One step equations are algebraic equations that can be solved in one step only. Such equations can be solved in just one step by adding, subtracting, multiplying, or dividing.

What is the correct way to solve an equation? ›

In order to solve equations, you need to work out the value of the unknown variable by adding, subtracting, multiplying or dividing both sides of the equation by the same value. Combine like terms. Simplify the equation by using the opposite operation to both sides. Isolate the variable on one side of the equation.

What is an important rule when solving equations? ›

But the main thing to keep certain about is that you MUST ALWAYS do exactly the same thing to both sides of the equation. So, you see that the main point is that you don't have to follow the order of operations as such, you just have to know how to apply the properties of the algebraic operations.

What are the rules for solving math equations? ›

The order of operations are the rules that tell us the sequence in which we should solve an expression with multiple operations. The order is PEMDAS: Parentheses, Exponents, Multiplication, and Division (from left to right), Addition and Subtraction (from left to right).

How to learn algebra easily? ›

Know the order of operations.

One of the trickiest things about solving an algebra equation as a beginner is knowing where to start. Luckily, there's a specific order for solving these problems: first do any math operations in parentheses, then do exponents, then multiply, then divide, then add, and finally subtract.

How to use VPA function in MATLAB? ›

Then, vpa is called on that double-precision number. For accurate results, convert numeric expressions to symbolic expressions with sym . For example, to approximate exp(1) , use vpa(exp(sym(1))) . If the second argument d is not an integer, vpa rounds it to the nearest integer with round .

How does histogram work in MATLAB? ›

Description. Histograms are a type of bar plot that group data into bins. After you create a Histogram object, you can modify aspects of the histogram by changing its property values. This is particularly useful for quickly modifying the properties of the bins or changing the display.

How to use simplify in MATLAB? ›

S = simplify( expr ) performs algebraic simplification of expr . If expr is a symbolic vector or matrix, this function simplifies each element of expr . S = simplify( expr , Name,Value ) performs algebraic simplification of expr using additional options specified by one or more Name,Value pair arguments.

How does MATLAB spline function work? ›

If y is a vector that contains two more values than x has entries, then spline uses the first and last values in y as the endslopes for the cubic spline. For example, if y is a vector, then: y(2:end-1) gives the function values at each point in x. y(1) gives the slope at the beginning of the interval located at min(x)

Top Articles
Erste Schritte mit der Remotedesktop-App für Windows
Erste Schritte mit dem iOS-Client
Public Opinion Obituaries Chambersburg Pa
Combat level
Academic Integrity
Richard Sambade Obituary
83600 Block Of 11Th Street East Palmdale Ca
Celsius Energy Drink Wo Kaufen
Www.paystubportal.com/7-11 Login
Gfs Rivergate
How Much Is Tj Maxx Starting Pay
Walthampatch
Kvta Ventura News
Nashville Predators Wiki
Espn Horse Racing Results
Roster Resource Orioles
Boston Gang Map
Sound Of Freedom Showtimes Near Cinelux Almaden Cafe & Lounge
Water Trends Inferno Pool Cleaner
Kayky Fifa 22 Potential
Dallas Mavericks 110-120 Golden State Warriors: Thompson leads Warriors to Finals, summary score, stats, highlights | Game 5 Western Conference Finals
Ivegore Machete Mutolation
Brazos Valley Busted Newspaper
Aol News Weather Entertainment Local Lifestyle
Jeffers Funeral Home Obituaries Greeneville Tennessee
Two Babies One Fox Full Comic Pdf
What Are The Symptoms Of A Bad Solenoid Pack E4od?
Ou Class Nav
Getmnapp
Wood Chipper Rental Menards
From This Corner - Chief Glen Brock: A Shawnee Thinker
Dhs Clio Rd Flint Mi Phone Number
27 Fantastic Things to do in Lynchburg, Virginia - Happy To Be Virginia
Chelsea Hardie Leaked
LG UN90 65" 4K Smart UHD TV - 65UN9000AUJ | LG CA
First Light Tomorrow Morning
Quality Tire Denver City Texas
Kaiju Paradise Crafting Recipes
Appraisalport Com Dashboard /# Orders
How to Destroy Rule 34
Solemn Behavior Antonym
Mta Bus Forums
Kerry Cassidy Portal
Ferguson Employee Pipeline
Scarlet Maiden F95Zone
فیلم گارد ساحلی زیرنویس فارسی بدون سانسور تاینی موویز
Elven Steel Ore Sun Haven
Haunted Mansion Showtimes Near Millstone 14
4Chan Zelda Totk
Msatlantathickdream
Campaign Blacksmith Bench
WHAT WE CAN DO | Arizona Tile
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 5881

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.