To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
kastepp
New to the neighborhood
kastepp
2 Posts

Help with Matlab Code

Hey!

I need some help with some code that i am trying to write.
It's basically trying to solve a system of equations Ax=b for x.

I have this much in a function file:

function [x] = jacobi_iterative(A,b,Nsteps)
Neq=length(A);
x=zeros(1,Neq);
for istep =1:1:Nsteps
for ix = 1:Neq
summat = 0;
for j = 1:Neq
if (j ~=ix)
summat = summat + A(ix+j)*x(j);
end
end
x(ix) = (b(ix) - summat)/A(ix,ix);
end
end



And I have this in another file:




Amatrix=input('Enter the matrix of coefficients of unknowns: ');
Bvector=input(' Enter the right side vector: ');
Niterations=50;
x_vector=jacobi_iterative(Amatrix,Bvector,Niterations);


disp('The answer is: ')
x_vector %#ok



The output for the program is a vector (lilke I want), but it is the wrong answer.

I am inputting Amatrix to be: [4 1 1; 2 5 1; 0 2 4] and the right side vector to be [5 -1 6]

The answer should be [1 -1 2]


Any suggestions you can make would be much appreciated!
shwaip
elaborate bot
shwaip
5,729 Posts
can you post your code in
PHP Code:
[code]code here[/code
tags so that it keeps the proper formatting?

thanks.
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
kastepp
New to the neighborhood
kastepp
2 Posts
oh! sorry about the tagging thing, but i figured out what the problems was. thanks for trying to help!


in my loop (line 9 of code in my function file), i had part of an equation as A(ix+j) when it should have actually of been A(ix,j)
Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Matlab code... FFT Analysis vince365 Matlab Help 5 2 Mar 2007 5:46pm
Remove Search Assistant, Shopping Wizard ETC..[inactive] phattbam Resolved / Inactive 12 13 Oct 2006 9:11pm
MATLAB code help please.... jennifer22cute Matlab Help 0 18 Sep 2006 8:53pm
Queued up results won't send!? Spinner Folding@Home 3 2 Sep 2004 2:10am
Printing out integer in MIPS f15e Web & Digital Media 11 20 Mar 2004 10:07pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 8:02am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.