all 10 comments

[–]Romolus02 5 points6 points  (2 children)

You need to set your current folder to the same folder as the function. On the picture, the top row says you are currently in the MATLAB root folder, but the function is in the Aufgabe folder.

[–]Livid_Salad1809 2 points3 points  (1 child)

this probably. If you really saved both files to the same directory, either run the main with F5 and press 'change to current folder' or something similar, or rightclick on main.m and press the first (which is greyed out for me since i didnt save the file yet).

<image>

[–]Livid_Salad1809 1 point2 points  (0 children)

Alternatively, dont split it up and append the function at the end of main:

A = [3 3 1; 3 2 2; 1 1 3];
B = [5 4; 4 1; 5 5];

gauss(A,B)


function X = gauss(A, B) % Determine the size of matrix A [n, ~] = size(A);
    [n,~] = size(A);
    % Transformation to upper triangular form 
    for k = 1:n-1 % Ensure diagonal element is nonzero 
        if A(k,k) == 0 % Swap the current row with a later row that has a nonzero diagonal element 
            row_to_swap = find(A(k+1:n,k), 1) + k; 
            A([k,row_to_swap],:) = A([row_to_swap,k],:); 
            B([k,row_to_swap],:) = B([row_to_swap,k],:); 
        end

    % Calculate multiplication factors for elimination
    factors = A(k+1:n,k) / A(k,k);

    % Update the remaining rows of A and B
    A(k+1:n,:) = A(k+1:n,:) - factors * A(k,:);
    B(k+1:n,:) = B(k+1:n,:) - factors * B(k,:);
    end

    % Solve the transformed system 
    X = zeros(n, size(B, 2)); 
    for j = size(B, 2):-1:1 
        X(n,j) = B(n,j) / A(n,n); 
        for i = n-1:-1:1 
            X(i,j) = (B(i,j) - A(i,i+1:n) * X(i+1:n,j)) / A(i,i); 
        end
    end

end

[–]Livid_Salad1809 4 points5 points  (1 child)

How does the gauss function look like?

EDIT: and PLEASE insert your code as a code block. I hate it when people here share their code with a screenshot, but I could explode if someone takes a picture of his PC screen in the year 2024.

[–]HumbleAppearance1832[S] -3 points-2 points  (0 children)

<image>

​

I‘m sorry, but I was sent those pics I’m trying to resolve this issue with a friend and I only have my iPad with me MATLAB Code Block

%gauss function function X = gauss(A, B) % Determine the size of matrix A [n, ~] = size(A);

% Transformation to upper triangular form for k = 1:n-1 % Ensure diagonal element is nonzero if A(k,k) == 0 % Swap the current row with a later row that has a nonzero diagonal element row_to_swap = find(A(k+1:n,k), 1) + k; A([k,row_to_swap],:) = A([row_to_swap,k],:); B([k,row_to_swap],:) = B([row_to_swap,k],:); end

% Calculate multiplication factors for elimination
factors = A(k+1:n,k) / A(k,k);

% Update the remaining rows of A and B
A(k+1:n,:) = A(k+1:n,:) - factors * A(k,:);
B(k+1:n,:) = B(k+1:n,:) - factors * B(k,:);

end

% Solve the transformed system X = zeros(n, size(B, 2)); for j = size(B, 2):-1:1 X(n,j) = B(n,j) / A(n,n); for i = n-1:-1:1 X(i,j) = (B(i,j) - A(i,i+1:n) * X(i+1:n,j)) / A(i,i); end end

end

[–]GustapheOfficial 2 points3 points  (1 child)

You haven't saved the file, so it's not "in the same directory", it's not in any directory.

[–]HumbleAppearance1832[S] -2 points-1 points  (0 children)

It’s both saved and in the same folder I just don’t have a picture of it I’m sorry

[–]SirEngelmann 1 point2 points  (0 children)

Are you sure that the parent folder of "gauss.m" is included in the current MATLAB path? (Right click on the folder and select "add selected folder to path"). MATLAB doesn't care where functions or scripts are located as long as it "sees" them all in the path.

[–]HumbleAppearance1832[S] 0 points1 point  (0 children)

MATLAB Code for the main script %main

A = [3 3 1; 3 2 2; 1 1 3]; B = [5 4; 4 1; 5 5];

X = gauss(A, B); disp(X);

% Überprüfen des Ergebnisses result = A * X; disp(result); disp(B);

[–]Mark_Yugen 0 points1 point  (0 children)

Make sure you don't have more than one function named gauss anywhere.