Borrar filtros
Borrar filtros

how i can change the variable? pleasee

2 visualizaciones (últimos 30 días)
Erwin Avendaño
Erwin Avendaño el 4 de Nov. de 2017
Comentada: Walter Roberson el 4 de Nov. de 2017
Look at the first code, if you realize and = (x. ^ 3) it is the same as E. ^ 3 that I want to do but in a general way in the code of my gui but what happens is that I do not know. The user for example x ^ 2 but I want to read my program to change it to E. ^ 2 and so it can work. My program asks for this to get the area under the curve and graph it
%FIRST CODE
a=input('Since: ');
b=input('until: ');
x=linspace(a,b,500);
y=(x.^3);
syms K;
syms n;
D=(b-a)/n;
E= a+((K-1)*D)+(D/2);
F= (E.^3)*D;
f= symsum (F,K,1,n);
A= limit(f,n,inf)
area(x,y);
grid on;
%SECOND CODE
a=str2double(get(handles.edit7,'string'));
b=str2double(get(handles.edit6,'string'));
x=linspace(a,b,500);
y=(get(handles.edit4,'string'));
j=char(y);
syms K;
syms n;
D=(b-a)/n;
E= a+((K-1)*D)+(D/2);
F=(j)*D;
f= symsum (F,K,1,n);
A= limit(f,n,inf)
axes(handles.axes3);
area(x,y);
grid on;

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Nov. de 2017
General matching to determine whether change of variable is appropriate requires subexpression pattern matching that is not available at the MATLAB level. It is possible in theory using the facilities inside the symbolic engine, MuPAD
For example you cannot detect that there is something to the 3rd power in any easy way. You can symvar() to extract the variables and then coeffs() with two outputs and look through the second output to find the cube of the variable and match it with its coefficient, and keep doing that until you find a variable is being cubed. However, this is not able to match a simple (x+1)^3 except by expanding out to x^3 + 3*x^2 + 3*x + 1, which is not what you might hope.
You can convert the expression to a character vector and do text processing... watch out for bracket nesting, though, which is something that no pure regular expression parser can handle.
At the MATLAB level there is no way to ask "does the expression contain something cubed?" .
In Maple you would be able to ask to indets(A, anything^3) or indets(A, `^`(anything,3)) (which are the same thing to Maple) or indets(A, specop(`^`)) to find all of the exponent operators (but you do have to be a bit careful in Maple, as negative exponents are sometimes constructed as 1 divided by the expression to the positive.)
  2 comentarios
Erwin Avendaño
Erwin Avendaño el 4 de Nov. de 2017
Thank you. Do you know how I could graph the area under a curve of any function in the matlab guide? to graph it in an axe
Walter Roberson
Walter Roberson el 4 de Nov. de 2017
You can do anything in GUIDE that you can do in MATLAB (but you will probably make an especially big mess if you "clear all")
Have a look at fill()

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by