sir, i am not able develop a matlab code to solve four transcendental equations using newton raphson method? i had tried till the creation of jacobian matrix but not able to substitute values in the jacobian matrix please help to solve this problem?

2 visualizaciones (últimos 30 días)
syms x1 x2 x3 x4 epsi;
g1=cos(x1)+cos(x2)+cos(x3)+cos(x4)-0.9424;
g2=cos(5*x1)+cos(5*x2)+cos(5*x3)+cos(5*x4);
g3=cos(7*x1)+cos(7*x2)+cos(7*x3)+cos(7*x4);
g4=cos(11*x1)+cos(11*x2)+cos(11*x3)+cos(11*x4);
g=[g1;g2;g3;g4];
x=[x1; x2; x3; x4];
epsi=10e-5;
j=jacobian(g,x);
for i=1:4
x(i,1)=input('enter the intial values\n')
end
disp(x)
f=subs(j);
j_inv=inv(f);
disp(-g);
k=subs(-g);
p=j_inv*k;
This is my code i am not able to substitute initial values in 'P' matrix. please help me to solve this.

Respuesta aceptada

Devineni Aslesha
Devineni Aslesha el 24 de Abr. de 2020
In the given code, the values are not substituted in the jacobian matrix because the initial values are assigned to the variable 'x' but the variables used in the equations are 'x1,x2,x3 and x4'. Please find the code below to substitute the initial values.
x1 = x(1,1);
x2 = x(2,1);
x3 = x(3,1);
x4 = x(4,1);
For more information, refer to this file exchange link
  5 comentarios
omkari sai krishna
omkari sai krishna el 3 de Mayo de 2020
Thank you mam for your support but still i am not able to solve this problem. I am giving the updated code for four nonlinear equations please give me suggestion where i am doing wrong.
clc;
close all;
clear all;
syms x y z v;
f=cosd(x)+cosd(y)+cosd(z)+cosd(v)-1.884;
fx=diff(f,x);fy=diff(f,y);fz=diff(f,z);fv=diff(f,v);
g=cosd(5*x)+cosd(5*y)+cosd(5*z)+cosd(5*v);
gx=diff(g,x);gy=diff(g,y);gz=diff(g,z);gv=diff(g,v);
h=cosd(7*x)+cosd(7*y)+cosd(7*z)+cosd(7*v);
hx=diff(h,x);hy=diff(h,y);hz=diff(h,z);hv=diff(h,v);
l=cosd(11*x)+cosd(11*y)+cosd(11*z)+cosd(11*v);
lx=diff(l,x);ly=diff(l,y);lz=diff(l,z);lv=diff(l,v);
n=input('Enter the number of decimal places:');
epsilon = 5*10^-(n+1)
x0 = input('Enter the x intial approximation:');
y0 = input('Enter the y intial approximation:');
z0 = input('Enter the z intial approximation:');
v0 = input('Enter the v initial value:');
xk = x0;yk = y0;zk = z0;vk = v0;
for i=1:100
fk=vpa(subs(f,[x y z v],[xk yk zk vk]));
gk=vpa(subs(g,[x y z v],[xk yk zk vk]));
hk=vpa(subs(h,[x y z v],[xk yk zk vk]));
lk=vpa(subs(l,[x y z v],[xk yk zk vk]));
fxk=vpa(subs(fx,[x y z v],[xk yk zk vk]));
fyk=vpa(subs(fy,[x y z v],[xk yk zk vk]));
fzk=vpa(subs(fz,[x y z v],[xk yk zk vk]));
fvk=vpa(subs(fv,[x y z v],[xk yk zk vk]));
gxk=vpa(subs(gx,[x y z v],[xk yk zk vk]));
gyk=vpa(subs(gy,[x y z v],[xk yk zk vk]));
gzk=vpa(subs(gz,[x y z v],[xk yk zk vk]));
gvk=vpa(subs(gv,[x y z v],[xk yk zk vk]));
hxk=vpa(subs(hx,[x y z v],[xk yk zk vk]));
hyk=vpa(subs(hy,[x y z v],[xk yk zk vk]));
hzk=vpa(subs(hz,[x y z v],[xk yk zk vk]));
hvk=vpa(subs(hv,[x y z v],[xk yk zk vk]));
lxk=vpa(subs(lx,[x y z v],[xk yk zk vk]));
lyk=vpa(subs(ly,[x y z v],[xk yk zk vk]));
lzk=vpa(subs(lz,[x y z v],[xk yk zk vk]));
lvk=vpa(subs(lv,[x y z v],[xk yk zk vk]));
xyzvk = [xk yk zk vk]'; %The old values of x,y,z
J = [fxk fyk fzk fvk;gxk gyk gzk gvk;hxk hyk hzk hvk;lxk lyk lzk lvk];
Fk = [fk gk hk vk]'; % Matrix of function values
xyzvkplus1 = (xyzvk - inv(J)*Fk);
if abs(xyzvkplus1 - xyzvk) < epsilon
break;
else
display('no solution');
end
end
xyzvans = xyzvkplus1-rem(xyzvkplus1,10^-n);
fprintf('The Root Matrix is :\n');
display(xyzvans);
for this code i am getting soltion more than 90 degrees.
Devineni Aslesha
Devineni Aslesha el 4 de Mayo de 2020
Editada: Devineni Aslesha el 4 de Mayo de 2020
In the above code, you are computing the answer 'xyzvans' even if there is no solution available. Use the return command after display('no solution'); to stop running this script when there is no solution. In this way, the answer will be computed only when the error value is less than epsilon.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by