Register to reply

Need help with Matlab code for gauss siedel i get errors, need imediat help

by fizzkilla
Tags: code, errors, gauss, imediat, matlab, siedel
Share this thread:
fizzkilla
#1
Jul1-12, 03:14 PM
P: 4
Please I need HELP IMEDIATLY

This is the error message that i get

??? Error using ==> gauss_sied
Too many input arguments.

Error in ==> HW_14 at 23
[x_wo, cnt, x_w,cntt] = gauss_sied(xo, A, b, es, lam);



clc
clear


C = [-8 1 -2 -20
2 -6 -1 -38
-3 -1 7 -34];

A = C(:,1:end-1);
b = C(:,end);


nr = length(b);

xo = ones(1,nr); % initial guess

lam = 1.2;
n = 4;
es = .5*10^(2-n);

[x_wo, cnt, x_w,cntt] = gauss_sied(xo, A, b, es, lam);

fprintf(' Solution to [A]{x} = {b}\n')
fprintf('*******************************************\n')
fprintf(' Without Relaxation With Relaxation\n')
fprintf(' ******************** ***************\n')
for i = 1:length(b)
fprintf(' x(i) = %.f x(i) = %.f\n',i,x_wo,i,x_w)
end
fprintf(' ******************** ***************\n')
fprintf(' %i iterations %i iterations\n',cnt,cntt)
fprintf('*******************************************\n')


Function program
function [x_wo, cnt,x_w cntt] = gauss_sied(xo, A, b, lam)
%Without Relaxation
nr = length(b);
ea = 1;
cnt = 0;


while ea > es
for i = 1 : nr
sm = 0;
for j = 1:nr
if i ~= j
sm = sm + A(i,j) * xo(j);
end
end
x_wo(i) = (b(i) - sm) / A(i,i);
end

ea = 100 * abs((x_wo-xo)./x_wo);

xo = x_wo;

cnt = cnt+1;
end

%With Relaxation

nr = length(b);
ea = 1;
cntt = 0;

while ea > es
for i = 1 : nr
sm = 0;
for j = 1:nr
if i ~= j
sm = sm + A(i,j) * xo(j);
end
end
x_w(i) = (b(i) - sm) / A(i,i);
end

ea = 100 * abs((x_w-xo)./x_w);
x_w = (lam*x_w) + (1 - lam)*xo;

xo = x_w;

cntt = cntt+1;
end
Phys.Org News Partner Science news on Phys.org
Security CTO to detail Android Fake ID flaw at Black Hat
Huge waves measured for first time in Arctic Ocean
Mysterious molecules in space
jhae2.718
#2
Jul1-12, 03:47 PM
PF Gold
jhae2.718's Avatar
P: 1,153
You're supplying 5 inputs to a function that is defined to have 4 inputs.

function [x_wo, cnt,x_w cntt] = gauss_sied(xo, A, b, lam)
called as:
[x_wo, cnt, x_w,cntt] = gauss_sied(xo, A, b, es, lam);
fizzkilla
#3
Jul1-12, 04:12 PM
P: 4
Now in my code I get another error

Error in ==> gauss_sied at 8
xo = x_wo;

Error in ==> HW_14 at 23
[x_wo, cnt, x_w,cntt] = gauss_sied(xo, es, lam, A, b);


Register to reply

Related Discussions
Errors with fortran code, help! Programming & Computer Science 7
Help with errors in my BinaryTree code Engineering, Comp Sci, & Technology Homework 6
(TexnicCenter) How to locate errors in code Math & Science Software 1
Gauss-Jacobi and Gauss-Siedel Calculus & Beyond Homework 0
Point out errors in code Engineering, Comp Sci, & Technology Homework 1