Borrar filtros
Borrar filtros

Please help me out to solve the following problem:

3 visualizaciones (últimos 30 días)
Muhammad Fahad
Muhammad Fahad el 26 de Mzo. de 2016
Respondida: Walter Roberson el 27 de Mzo. de 2016
Actually I want to solve the system of two coupled differential equations in MATLAB by using implicit Euler's Method.My teacher suggests me to use the command "fsolve".Here I am providing the MATLAB code that I construct.I know there must be a very stupid error at line 13 but anyways help me to solve this problem:
clear all
clc
f = @(y) [-80.6*y(1)+119.4*y(2); 79.6*y(1)-120.4*y(2)];
h=1/100;
y(:,1)=[1 ; 4];
t(1)=0;
for i =1:2
y(:,i+1)=fsolve(@(z) -z+y(:,i)+h*f(z),[-10 10])
t(i+1)=t(i)+h;
end
plot(t,y(1,:),'b',t,y(2,:),'b')
hold on
ts=0:0.001:1;
ys(1,:)=(3)*exp(-ts)+(-2)*exp(-200*ts);
ys(2,:)=(2)*exp(-ts)+(2)*exp(-200*ts);
plot(ts,ys(1,:),'r',ts,ys(2,:),'g')
  1 comentario
Walter Roberson
Walter Roberson el 26 de Mzo. de 2016
This is your 4th copy of the same question. You did not include the actual error message in any of them.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Mzo. de 2016
You have
y(:,i+1)=fsolve(@(z) -z+y(:,i)+h*f(z),[-10 10])
fsolve invokes the function with a row vector, so z will be a row vector. But in -z+y(:,i)+h*f(z), y(:,i) is a column vector and f(z) is a column vector, so you are trying to add a row vector and a column vector.
Probable fix:
y(:,i+1)=fsolve(@(z) -z(:) + y(:,i) + h*f(z), [-10 10])

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by