Water Tabo
Water Tabo

Reputation: 1

Scilab syntax error, unexpected end of line, expecting "," or ) its on line 14 and i dont why theres an error its correct thought

SO basically it keeps saying error at line 14 which is the "else" code is at i dont get it why it is synta error please help

clear
clc

function f=f(x)
    f = x^3 + 2*x^2 - 3*x -1
endfunction

disp ("sample input"): regulaFalsi (1,2,10^-4, 100)

function regulaFalsi(a, b, TOL, N)
    i = 1
    FA = f(a)
    finalOutput  =(i, a , b , a + (b-a)/2, f(a + (b-a) /2)
    
    printf ("%-20s%-20s%-20s%-20s%-20s\n","n","a_n","b_n","p_n","f(p_n)")
    
    while (i <= N),
        p = (a*f(b)-b*f(a))/f(b) - f(a))
        FP = f(p)
        
        if (FP == 0 | aba (f(p)) < TOL) then
            break
        else 
printf("%-20.8g %-20.8g %-20.8g %-20.8g %-20.8g\n", i, a, b, p, f(p))
            end
            i = i + 1
            if (FA + FP > 0) then
                a = p
            else 
                b = p
            end
    end

I have been trying to fix this code for my assignment but i dont know why it keeps giving me syntax error

Upvotes: 0

Views: 449

Answers (2)

S. Gougeon
S. Gougeon

Reputation: 911

In addition to Serge's answer:

  • regulaFalsi() is defined ''after'' the first call to it. Sure that this first call will fail.

  • Although finalOutput is unused (and so likely useless), the definition finalOutput =(i, a , b , a + (b-a)/2, f(a + (b-a) /2) misses a closing ). It is likely the origin of the error.

  • f(): here it works, but in a more general way it is not a good idea to name the function's output with the same name as the function itself.

  • putting clear at the head of your script(s) is not really a good idea. It is most often useless, and most often violent enough to erase useful objects, like libraries loaded on the fly, etc.

When you report an error, please report the full actual error message. It is most often more useful than only comments or "personal translation" of the error.

Upvotes: 1

Serge Steer
Serge Steer

Reputation: 446

No indentation does not matter but you wrote

disp ("sample input"): regulaFalsi (1,2,10^-4, 100)

instead of

disp ("sample input"); regulaFalsi (1,2,10^-4, 100)

a colon : instead of a semi colon ;

Moreover an "end" is missing to close the regulaFalsi function definition

Upvotes: 1

Related Questions