LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Octave/Matlab (https://www.linuxquestions.org/questions/programming-9/octave-matlab-4175663312/)

Rpin 10-28-2019 02:38 PM

Octave/Matlab
 
I'm newbie here, I'm a math student. Right now I'm doing a calculus work. I need to create an algoritm using octave/matlab, to solve non-linear systems. I found that code, but I can't compile it. I'm learning it yet. Anyone could help me?

function [x] = newton(F,JF,x0,TOL,N)
x = x0
k = 1
#iteracoes
while (k <= N)
#iteracao de Newton
delta = -inv(JF(x))*F(x)
x = x + delta
#criterio de parada
if (norm(delta,’inf’)<TOL) then
return
endif
k = k+1
endwhile
error('Maximum of iterations!')
endfunction

scasey 10-28-2019 03:04 PM

Oops...duplicate post. see #3

scasey 10-28-2019 03:04 PM

What language is that code? What are the specifications of your system? What have you tried to do?

rtmistler 10-29-2019 07:15 AM

Quote:

Originally Posted by scasey (Post 6051560)
What language is that code? What are the specifications of your system? What have you tried to do?

Matlab has their own libraries and variable types which greatly aids their environment which is obviously math focused.

This may be exactly that, or it may be a different language, designed with the same points in mind.

@Rpin,

Welcome to LQ.

Perhaps you ought to share if you have any information about compiling in general. Were you given a fundamental compile command, and a simple example which works with it? Or instead what tools and interface were you given to be able to create, edit, test, and submit your efforts using octave/matlab? Or when you say, "I'm learning it yet", was that a grammar incorrect statement to indicate that you hadn't yet learned how to compile, but it is an eventual part of the course, or that you're just starting with compiling these programs, but you haven't picked it up too well as yet? Either case, there likely should be aid available from a lab manager, instructor, or teaching assistant for that, please do seek them out to aid you with compiling programs.

For this problem, it might be better instead to write your intended algorithm, in an algorithm description language, which is very much similar to what that shows, but has more descriptiveness included with it. Like explains what F, JF, x0, TOL, and N are to represent.

Great that you found something, but do you understand it as well as agree with the logic which is written there? My read is that it is some calculation using Newtons, using change (delta), and performing N iterative calculations, making sure part of it doesn't exceed a TOL limit. OK, I'm rusty on my physics, but I guess the point of this here is that you're calculating upon a rate of change, which is linear algebra.

To be honest, my concern here is that you wish to just grab something you found on the web, and I'd half bet that if you got it compiled with zero fuss, that you'd turn it in? Call me incorrect there, sorry. I get it that sometimes one wishes to show progress and be successful, however it also is beneficial to ask if you're entirely out of wits with understanding an assignment so that you can get over that blocking point and move on to more interesting calculations. I'm suspecting that the whole point here is to start learning the octave/matlab coding conventions so that you'll master them and thus be able to express equations of greater and greater complexity. Best to start with the simple ones, versus debugging something, that someone else wrote.

Again, just a guess here, but if I was an instructor and one or more of my students was having difficulties even starting assignments, I'd like to know that so I could provide more adequate background for them.


All times are GMT -5. The time now is 07:36 AM.