Subs Command for Multivariable Function (2024)

7vues (au cours des 30derniers jours)

Afficher commentaires plus anciens

Alex Santizo le 7 Fév 2020

  • Lien

    Utiliser le lien direct vers cette question

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function

  • Lien

    Utiliser le lien direct vers cette question

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function

Commenté: Walter Roberson le 11 Déc 2020

Ouvrir dans MATLAB Online

syms x y

g=(1/2)*e^(-2*x/3).*tan(y+1);

subs(g,x,0.3);

subs(g,y,-0.7);

0commentaires

Afficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Connectez-vous pour répondre à cette question.

Réponses (2)

Walter Roberson le 7 Fév 2020

  • Lien

    Utiliser le lien direct vers cette réponse

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#answer_414268

  • Lien

    Utiliser le lien direct vers cette réponse

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#answer_414268

For the case of scalars

subs(g, [x, y], [0.3,-0.7])

For the case of non-scalars

subs(g, {x, y}, {newx, newy})

3commentaires

Afficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien

Alex Santizo le 7 Fév 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_794546

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_794546

Ouvrir dans MATLAB Online

For some reason I keep getting an error in this line of code.

g=(1/2)*e^(-2*x/3).*tan(y+1);

%% Says there is an error on this line and Im not understanding where.

Ashwin Shibu le 11 Déc 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_1199035

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_1199035

i dont think there shd be s dot after e^(-2*x/3)

Walter Roberson le 11 Déc 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_1200995

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_1200995

Ouvrir dans MATLAB Online

Dot between the e and the ^ is needed if x might be non-scalar. Dot between the ) and the *tan is needed if x and y might both be non-scalar.

That said, exp() is recommended instead of e^

g=(1/2)*exp(-2*x/3).*tan(y+1);

As a matter of style: I recommend that .* be used in any case involving variables unless you deliberately mean matrix multiplication (inner product). I would suggest * with scalars only for very simple constant multiples, such as 3*x -- but not, for example, x*y even if you know that x and y are both scalars. Using .* explicitly saves thinking by other people reading the code about whether you really meant matrix multiplication and saves programmers reading your code tracing back to prove that in every possible code path to that point, that x and y are guaranteed to be scalars.

Connectez-vous pour commenter.

Vladimir Sovkov le 7 Fév 2020

  • Lien

    Utiliser le lien direct vers cette réponse

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#answer_414269

  • Lien

    Utiliser le lien direct vers cette réponse

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#answer_414269

Ouvrir dans MATLAB Online

If e^ is the exponent and if you want to estimate the result numerically (from the question it is not quite clear what you want), you can use

syms x y

g=(1/2)*exp(-2*x/3).*tan(y+1);

double(subs(subs(g,x,0.3),y,-0.7))

2commentaires

Afficher AucuneMasquer Aucune

Alex Santizo le 7 Fév 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_794547

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_794547

The question I am trying to solve is to evaluate that function at x & y are equal to the listed values using the subs command and by conversion into a matlab function.

Vladimir Sovkov le 7 Fév 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_794552

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/504156-subs-command-for-multivariable-function#comment_794552

Modifié(e): Vladimir Sovkov le 7 Fév 2020

Ouvrir dans MATLAB Online

This case the code above should work. Though, you can do it easier and with faster computation avoiding symbolic computations as, e.g. (there are many ways to do it)

function g = myfunc (x,y)

g=(1/2)*exp(-2*x/3).*tan(y+1);

end

and call it as

g=myfunc(0.3,-0.7)

The error in your code is because Matlab is unaware what the variable "e" is. If you mean the exponent function, use "exp" instead, as in the code above. If you actually defined "e" somewhere before, the error can be with nonscalar values; if you mean the element-wise operation, use ".^" instead of "^" analogous to ".*" in the following part.

Connectez-vous pour commenter.

Connectez-vous pour répondre à cette question.

Voir également

Catégories

Mathematics and OptimizationSymbolic Math ToolboxSymbolic Computations in MATLABConversion Between Symbolic and Numeric

En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange

Tags

  • subs
  • command
  • syms

Community Treasure Hunt

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

Start Hunting!

Une erreur s'est produite

Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.


Translated by Subs Command for Multivariable Function (9)

Subs Command for Multivariable Function (10)

Sélectionner un site web

Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .

Vous pouvez également sélectionner un site web dans la liste suivante :

Amériques

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

Asie-Pacifique

Contactez votre bureau local

Subs Command for Multivariable Function (2024)

References

Top Articles
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 5879

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.