how to type sin^2(x) instead of sin(x)^2

i cant type it it always gives error. I just want sin^2(x), but i can only type in sin(x)^2
i left a pic to the type of thing that i want to get.

5 comentarios

James Tursa
James Tursa el 10 de Dic. de 2020
MATLAB syntax only supports the sin(x)^2 (or sin(x).^2 if you want element-wise) version. Are you asking how to input an expression in your desired format and have MATLAB interpret it as you want? Or are you asking how to display expressions in your desired format?
John Smith
John Smith el 10 de Dic. de 2020
I want 2 to be above sin instead instead at the x because im trying to do homework. I dont want to display, i just want to type it in correctly to get the correct result for my homework.
James Tursa
James Tursa el 10 de Dic. de 2020
That would mean writing your own parser, which would be a lot of work in general just to be able to input the syntax you want. Maybe the regular expression engine could be used to accomplish this, but it will probably be simpler if you just use the native syntax that MATLAB supports.
John D'Errico
John D'Errico el 10 de Dic. de 2020
Editada: John D'Errico el 10 de Dic. de 2020
Think of it as if you went to a foreign country, and wanted to talk to people using your own adulterated version of their language. Would you be surprised if many people were insulted? If you want to be understood, you will need to learn the language, even if you like your personal version better.
While sin^2 may be correct in your view, it is not valid MATLAB syntax, and it matters not how badly you want that to be true.

Iniciar sesión para comentar.

Respuestas (1)

John D'Errico
John D'Errico el 10 de Dic. de 2020

0 votos

That is just MATLAB syntax. You can want it to be different, but you really have no choices. When you use a language, you need to learn the syntax. Sorry, but you do.
Is it a syntax that some people use? Well, yes. But computers are not very flexible. This is not even something that I would see you being able to write some special class of your own. (That is one fix that works for a lot of problems, if you are willing to do the work.) But in this case, I don't even see it as something you could easily implement, even if you were willing to make the effort, because this gets into the basic parsing rules of MATLAB.
You could theoretically pose an enhancement request. You would need to send that to The MathWorks directly. I'd not get my hopes up high though of it happening any time soon, because this would involve a fairly significant change in how MATLAB would need to parse code.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Dic. de 2020

Editada:

el 10 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by