How to use FSOLVE with multiple variables?
Im trying to solve a problem that involves multiple variables and a paramether that chances on every interection.
If I try to run my main file appers this error:
error: ‘x’ undefined near line 40, column 37
error: called from
main at line 40 column 17
If someone could helps me with this problem I´ll be so greatfull.
>>
My code:
%%%%%%file 1 (main)
%fixed value
global M
M = 33180;
L = leitura_arq(‘arquivo1.txt’, M);
%h = 0.0001;
chute_inicial = [1,1];
% resolve sistem of equations
[x, fval, info] = fsolve (@equacoes(x, M, L), chute_inicial)
%%% FILE 2 (equacoes)
%file used to describe the equations
function F = equacoes (x, M, L)
%valores fixos
M = 33180;
%L = leitura_arq(‘arquivo1.txt’, M);
%x(1) = Betha
%x(2) = Lambda
F(1) = (x(1) * x(2) * M) – (x(1) * (1 / x(2))^(x(1) – 1) * somatorio1(L, x(1)));
F(2) = (M * log(1 / x(2))) + (x(2) * M) + log(sum(L)) – log(x(1));
end
%%%FILE 3 (leitura_arq)
% this file read a csv file and save these values
function L = leitura_arq(arquivo1, M)
L = zeros(1, M); % Inicializa o vetor com zeros
fid = fopen(arquivo1, ‘r’);
if fid == -1
error(‘Erro na abertura do arquivo.’);
else
disp(‘Arquivo aberto com sucesso.’);
for i = 1:M
L(i) = fscanf(fid, ‘%f’, 1);
end
fclose(fid);
end
end
%%% FILE 4 (somatorio1)
% this file do the interection and sum
function s1 = somatorio1(L, betha)
s1 = sum(L .^ betha);
endIm trying to solve a problem that involves multiple variables and a paramether that chances on every interection.
If I try to run my main file appers this error:
error: ‘x’ undefined near line 40, column 37
error: called from
main at line 40 column 17
If someone could helps me with this problem I´ll be so greatfull.
>>
My code:
%%%%%%file 1 (main)
%fixed value
global M
M = 33180;
L = leitura_arq(‘arquivo1.txt’, M);
%h = 0.0001;
chute_inicial = [1,1];
% resolve sistem of equations
[x, fval, info] = fsolve (@equacoes(x, M, L), chute_inicial)
%%% FILE 2 (equacoes)
%file used to describe the equations
function F = equacoes (x, M, L)
%valores fixos
M = 33180;
%L = leitura_arq(‘arquivo1.txt’, M);
%x(1) = Betha
%x(2) = Lambda
F(1) = (x(1) * x(2) * M) – (x(1) * (1 / x(2))^(x(1) – 1) * somatorio1(L, x(1)));
F(2) = (M * log(1 / x(2))) + (x(2) * M) + log(sum(L)) – log(x(1));
end
%%%FILE 3 (leitura_arq)
% this file read a csv file and save these values
function L = leitura_arq(arquivo1, M)
L = zeros(1, M); % Inicializa o vetor com zeros
fid = fopen(arquivo1, ‘r’);
if fid == -1
error(‘Erro na abertura do arquivo.’);
else
disp(‘Arquivo aberto com sucesso.’);
for i = 1:M
L(i) = fscanf(fid, ‘%f’, 1);
end
fclose(fid);
end
end
%%% FILE 4 (somatorio1)
% this file do the interection and sum
function s1 = somatorio1(L, betha)
s1 = sum(L .^ betha);
end Im trying to solve a problem that involves multiple variables and a paramether that chances on every interection.
If I try to run my main file appers this error:
error: ‘x’ undefined near line 40, column 37
error: called from
main at line 40 column 17
If someone could helps me with this problem I´ll be so greatfull.
>>
My code:
%%%%%%file 1 (main)
%fixed value
global M
M = 33180;
L = leitura_arq(‘arquivo1.txt’, M);
%h = 0.0001;
chute_inicial = [1,1];
% resolve sistem of equations
[x, fval, info] = fsolve (@equacoes(x, M, L), chute_inicial)
%%% FILE 2 (equacoes)
%file used to describe the equations
function F = equacoes (x, M, L)
%valores fixos
M = 33180;
%L = leitura_arq(‘arquivo1.txt’, M);
%x(1) = Betha
%x(2) = Lambda
F(1) = (x(1) * x(2) * M) – (x(1) * (1 / x(2))^(x(1) – 1) * somatorio1(L, x(1)));
F(2) = (M * log(1 / x(2))) + (x(2) * M) + log(sum(L)) – log(x(1));
end
%%%FILE 3 (leitura_arq)
% this file read a csv file and save these values
function L = leitura_arq(arquivo1, M)
L = zeros(1, M); % Inicializa o vetor com zeros
fid = fopen(arquivo1, ‘r’);
if fid == -1
error(‘Erro na abertura do arquivo.’);
else
disp(‘Arquivo aberto com sucesso.’);
for i = 1:M
L(i) = fscanf(fid, ‘%f’, 1);
end
fclose(fid);
end
end
%%% FILE 4 (somatorio1)
% this file do the interection and sum
function s1 = somatorio1(L, betha)
s1 = sum(L .^ betha);
end fsolve, multiplevariables MATLAB Answers — New Questions