Roots of a function
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Umar Farooq
el 30 de Mzo. de 2016
Comentada: Torsten
el 31 de Mzo. de 2016
I have two equations:
y1 = 2sinx1;
y2 = 2cos^2(x1) + 3sin(2x2+3);
here y1 = 0 while y2 = 1.
Can anyone please tell me which approach would be the best to find out the values of x1 and x2.
Thank you.
1 comentario
Respuesta aceptada
Torsten
el 31 de Mzo. de 2016
Editada: Torsten
el 31 de Mzo. de 2016
Try this:
function driver
y=zeros(1,2);
y(1)=0;
y(2)=1;
x0=zeros(1,2);
x=fsolve(@(x)HW1(x,y),x0)
function res = HW1(x,y)
res(1)=y(1)-2*sin(x(1));
res(2)=y(2)-(2*cos(x(1))^2 + 3*sin(2*x(2) + 3));
Best wishes
Torsten.
2 comentarios
Torsten
el 31 de Mzo. de 2016
Your equations don't have a unique solution. So - depending on the starting guess x0 - you'll get different solutions for x. Do you have any condition on x that could make the solution unique ?
Best wishes
Torsten.
Más respuestas (1)
Vlad Miloserdov
el 30 de Mzo. de 2016
if you still need this
A=solve('0 = 2*sin(x1)','1 = 2*cos(x1)^2 + 3*sin(2*x2+3)','x1','x2');
% first ans
A.x1(1)
A.x2(1)
% second ans
A.x1(2)
A.x2(2)
5 comentarios
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!