Question about vpasolve to solve a nonlinear equation with mutliple... (2024)

7 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Xiao Lai am 26 Sep. 2018

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables

Kommentiert: Walter Roberson am 27 Sep. 2018

Akzeptierte Antwort: John D'Errico

In MATLAB Online öffnen

Hello everyone,

Recently I'm solving a nonlinear equation with mutliple variables. For example:

x=sym('a%d%d',[2,1]);

a=vpasolve(x.a11+tan(x.a12)==0,x,'random',true)

I know "vpasolve" can solve questions about multiple equations and variables. But I only have one equation, and the number of variables depends on the specific problem. So I want to find a more flexible codes. Brief, how can I solve a nonlinear equation with changeable number of variables?

Best,

Xiao

1 Kommentar

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

Walter Roberson am 26 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614531

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614531

In MATLAB Online öffnen

eqn = x(1)+tan(x(2))==0

a = vpasolve(eqn, x,'random',true);

If eqn does not reference some of the variables in x, then those variables will end up with numeric values that could be just about anything.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

John D'Errico am 26 Sep. 2018

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#answer_338489

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#answer_338489

Bearbeitet: John D'Errico am 26 Sep. 2018

In MATLAB Online öffnen

You have one equation, in more than one unknown. There is no solution for x. Or, said differently, there may generally be infinitely many solutions.

Had you asked to solve for one variable, as a function of the others, that you could do, well potentially so. It would depend on the actual equation. But VPASOLVE would not generally be the tool to solve the problem. VPASOLVE is a numerical tool, that works in high precision. You would just then use solve anyway.

For example:

syms x y

EQN = x+y == 0;

vpasolve(EQN,x)

ans =

-1.0*y

So for a trivial polynomial equation of low order, VPASOLVE did not have a hiccup. But, even for an almost as trivial one that is not trivially polynomial, we see:

EQN = sin(x+y) == 0;

vpasolve(EQN,x)

Error using mupadengine/feval (line 187)

Symbolic parameters not supported in nonpolynomial equations.

Error in sym/vpasolve (line 172)

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

solve(EQN,x)

ans =

-y

So you can use solve, at least in that case. Of course, not all problems have a solution. In your example I can do this:

a = solve(x(1)+tan(x(2))==0,x(1))

a =

-tan(a21)

6 Kommentare

4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden

Xiao Lai am 26 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614641

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614641

Hello John,

Thanks for your answer. I'm afraid that I didn't give a clear explanation about my problem. In fact, the final goal is to get the five solution of infinite solutions. For example, a problem like det(A(x1,x2...,xn))==0, where A is a matrix, x1 to xn are parameters. And N is the number of parameters, which is changeable.To me, numerical solution is enough, I don't need analytical ones.

Best,

Xiao

Walter Roberson am 26 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614774

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614774

In MATLAB Online öffnen

vpasolve(sin(x+y)==0)

is fine, as is vpasolve(sin(x + y),[x,y]) or vpasolve() with any list of variables that includes all variables present in the equation works.

Xiao Lai am 27 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614845

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614845

Yes, but if I don't the number of variables, how could I achieve this? I means if the variables is stored in a symbolic vector.

Xiao Lai am 27 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614850

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614850

In MATLAB Online öffnen

An easy example, thanks for all of your help.

size =4;

a=sym('a', [1 size])

b=vpasolve(sin(a(1)+a(2)+a(3)+a(4))==0,'random',true)

for i=1:1:size

getfield(b,strcat('a', num2str(i)))

end

Walter Roberson am 27 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614852

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614852

If you simply do not mention any variable names to solve for, then it will solve for all of the mentioned variables. With the single output form of vpasolve() the result will be a struct with one field for each variable.

If you have a complete list of all of the variables that might potentially be present, then you can mention the complete list as the second parameter of vpasolve(). With the single output form of vpasolve() the result will be a struct with one field for each of those variables. Even the "unused" ones will have numeric values (that could be just about anything.) This is not as efficient as not mentioning any of them, or using symvar() to determine the list of variables and mentioning only those, but mentioning the complete list can make some interfaces easier since it can reduce the amount of post-processing you need to do.

Walter Roberson am 27 Sep. 2018

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614857

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/420816-question-about-vpasolve-to-solve-a-nonlinear-equation-with-mutliple-variables#comment_614857

In MATLAB Online öffnen

Instead of that loop you have, the better approach would probably be

fn = fieldnames(b);

for K = 1 : length(fn)

thisfield = fn{K};

fprintf('%s = ', thisfield);

disp( b.(thisfield) )

end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABLanguage FundamentalsData TypesNumeric TypesLogical

Mehr zu Logical finden Sie in Help Center und File Exchange

Tags

  • vpasolve
  • multiple variables
  • nonlinear equation

Produkte

  • MATLAB

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 Question about vpasolve to solve a nonlinear equation with mutliple... (10)

Question about vpasolve to solve a nonlinear equation with mutliple... (11)

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

Kontakt zu Ihrer lokalen Niederlassung

Question about vpasolve to solve a nonlinear equation with mutliple... (2024)

References

Top Articles
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated:

Views: 6415

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.