How do I correctly use vpasolve? (2024)

73 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Goncalo Costa am 17 Nov. 2022

  • Verknüpfen

    Direkter Link zu dieser Frage

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

  • Verknüpfen

    Direkter Link zu dieser Frage

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

Kommentiert: Walter Roberson am 18 Nov. 2022

In MATLAB Online öffnen

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 Kommentar

-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Star Strider am 17 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.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.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Antworten (2)

Torsten am 17 Nov. 2022

  • Verknüpfen

    Direkter Link zu dieser Antwort

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

  • Verknüpfen

    Direkter Link zu dieser Antwort

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

Bearbeitet: Torsten am 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 Kommentare

4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden

Goncalo Costa am 17 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.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 am 17 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

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

In MATLAB Online öffnen

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 am 17 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.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 am 17 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

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

Bearbeitet: Torsten am 17 Nov. 2022

In MATLAB Online öffnen

@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 am 18 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.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 am 18 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.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?

Melden Sie sich an, um zu kommentieren.

Walter Roberson am 17 Nov. 2022

  • Verknüpfen

    Direkter Link zu dieser Antwort

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

  • Verknüpfen

    Direkter Link zu dieser Antwort

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

In MATLAB Online öffnen

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 Kommentare

Keine anzeigenKeine ausblenden

Goncalo Costa am 18 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.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 am 18 Nov. 2022

Direkter Link zu diesem Kommentar

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

  • Verknüpfen

    Direkter Link zu diesem Kommentar

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

In MATLAB Online öffnen

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.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABLanguage FundamentalsLoops and Conditional Statements

Mehr zu Loops and Conditional Statements finden Sie in Help Center und 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!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by How do I correctly use vpasolve? (13)

How do I correctly use vpasolve? (14)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

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

Europa

  • 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)

Asien-Pazifik

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

Kontakt zu Ihrer lokalen Niederlassung

How do I correctly use vpasolve? (2024)

FAQs

What is the precision of Vpasolve? ›

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

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 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.

How to solve an equation with a variable on both sides? ›

Solving Variables on Both Sides of the Equation
  1. Combine like Terms (add things that have the same variable)
  2. Distribute when needed (multiply each of the things inside the parentheses)
  3. Add the additive inverse of terms to both sides.
  4. Multiply by the multiplicative inverse to both sides.

What is the accuracy of precision balance? ›

Precision Weighing Balances

A precision balance has a lower readability than an analytical balance, as it typically measures to the nearest 0.1-0.01g, but tends to have a higher capacity.

What are digits of precision? ›

Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2 . In SQL Server, the default maximum precision of numeric and decimal data types is 38.

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 epcrs and Vfcp? ›

The Voluntary Fiduciary Correction Program (VFCP) is one of the plan correction programs maintained by the Department of Labor. Unlike EPCRS, which focuses on compliance with the tax rules, this program focuses on fiduciary duties.

Why Dsolve is used in MATLAB? ›

dsolve sorts the dependent variables alphabetically, and then assigns the solutions for the variables to output variables or symbolic arrays.

What is the equivalent of Vpasolve in Python? ›

While MATLAB calls it variable precisions, other areas mostly call it arbitrary precision. You closest equivalent to vpasolve would be using mpmath in python.

How to use vpa function in MATLAB? ›

xVpa = vpa( x ) uses variable-precision arithmetic (arbitrary-precision floating-point numbers) to evaluate each element of the symbolic input x to at least d significant digits, where d is the value of the digits function. The default value of digits is 32.

What does empty sym 0 by 1 mean? ›

Direct link to this answer

solve returns 'Empty sym: 0-by-1' when there is no explicit solution to the equation. The equation has no solution because of the assignment q=1:3; when you use an array like that in the line where the equation is defined it defines it as: [3*x + 3 == 0, 3*x + 4 == 0, 3*x + 5 == 0]

How do I move a variable to the other side of an equation? ›

RULE #2: to move or cancel a quantity or variable on one side of the equation, perform the "opposite" operation with it on both sides of the equation. For example if you had g-1=w and wanted to isolate g, add 1 to both sides (g-1+1 = w+1).

How to solve an equation with two variables? ›

How do you solve an equation with 2 variables? A two-variable equation is solved by plugging in x = 0 and solving for y and then plugging in y = 0 and solving for x. These results give you the x and y intercepts of the graph. By joining those two points, the equation will be represented.

How to solve the variable? ›

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 floating point scale? ›

The value that can be represented by a single precision floating point number is approximately 6 or 7 decimal digits of precision. A double precision, floating-point number is a 64-bit approximation of a real number.

What is the precision of decimals in vertica? ›

Vertica and Transformation Data Types
Vertica Data TypeTransformation Data TypeDescription
NumericDecimalPrecision 1 to 28, scale 0 to 28
RawBinary1 to 104,857,600 bytes
RealDoublePrecision 15
SmalldatetimeDate/TimeJan 1, 0001 A.D. to Dec 31, 9999 A.D. (precision to the nanosecond)
24 more rows

What is the precision of gravimetric analysis? ›

Gravimetric analysis, if methods are followed carefully, provides for exceedingly precise analysis. In fact, gravimetric analysis was used to determine the atomic masses of many elements in the periodic table to six figure accuracy.

What is the precision of MIPS floating point? ›

MIPS has 32 single precision (32 bit) floating point registers. $f0 is not special (it can hold any bit pattern, not just zero).

Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 5647

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.