How to solve equation with ten unknowns with Fourier Analysis

조회 수: 2 (최근 30일)
Valerio Gianforte
Valerio Gianforte 2020년 3월 17일
답변: Rik 2020년 3월 18일
Hi Everyone,
I have to compute ten unknowns in one equation and I have no idea how to do. Is there someone can help me? I'm attacching the code and the files below. Thanks
format long g
folderData = 'D:\Valerio\data\ACCESS1.0';
filePattern = fullfile(folderData, '*.xlsx');
xlsFiles = dir(filePattern);
nFiles = length(xlsFiles);
for ii = 1:nFiles
filename = fullfile(xlsFiles(ii).folder, xlsFiles(ii).name);
files{ii} = xlsread(filename);
end
IPCC = files(1);
ERA5 = files(2);
IPCC_data = unique(IPCC{:,1},'rows');
ERA5_data = unique(ERA5{:,1},'rows');
dt_IPCC = datetime([IPCC_data(:,1:3) IPCC_data(:,4)/1E4 repmat([0 0],size(IPCC_data,1),1)]);
dt_ERA5 = datetime([ERA5_data(:,1:4) repmat([0 0],size(ERA5_data,1),1)]);
[~,ia,ie] = intersect(dt_IPCC,dt_ERA5);
tt_IPCC_ERA5 = timetable(dt_IPCC(ia),IPCC_data(ia,5:end),ERA5_data(ie,5:end));
tt_IPCC_ERA5.Properties.VariableNames = {'IPCC','ERA5'};
IPCC = tt_IPCC_ERA5.IPCC;
ERA5 = tt_IPCC_ERA5.ERA5;
f = ERA5(:,1); %Hs from ERA5
dir_ERA5 = ERA5(:,3);
x1 = IPCC(:,1); %Hs from IPCC
x2 = IPCC(:,3); %Dir from IPCC
f = @(F,x)(F(1)+F(2)*cos(2*pi*(x2/360)-F(3))+F(4)*cos(4*pi*(x2/360)-F(5))*x1^((F(6)+F(7)*cos(2*pi*(x2/360)-F(8))+F(9)*cos(4*pi*(x2/360)-F(10)))));
I have to compute all values of F with Fourier Analysis. Thanks.
  댓글 수: 3
Valerio Gianforte
Valerio Gianforte 2020년 3월 17일
편집: Valerio Gianforte 2020년 3월 17일
no, I don't know to use 'fit'. I'll take a look at this command.
Valerio Gianforte
Valerio Gianforte 2020년 3월 18일
I can't use 'fit' because I have not 'Curve fitting Toolbox' and ' Predictive Maintenance Toolbox '.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jon
Jon 2020년 3월 17일
If you have the optimization toolbox you can use fsolve
  댓글 수: 2
Valerio Gianforte
Valerio Gianforte 2020년 3월 17일
No, I have not that toolbox.
Jon
Jon 2020년 3월 17일
There are also some nonlinear equation solvers in the MATLAB File Exchange.
If you go to the MATLAB file exchange and search using the terms solve system of nonlinear equation
you will find some possibilities. I've never used any of these so I can not provide any recommendations regarding how well they work.
Here are a few to get you started:

댓글을 달려면 로그인하십시오.


Rik
Rik 2020년 3월 18일
The code below will work in base Matlab (i.e. it doesn't require any toolbox). Note that the fminsearch function is relatively sensitive to the initial condition. It may fail to find the global optimum, or even to find a good local optimum. If you want better performance you should switch to a different algorithm and/or consider purchasing the curve fitting toolbox.
%syntax:
%x - x values
%y - vector with true output
%initial_guess - vector with your initial estimates
%f - function that converts (initial_guess,x) input to the same shape as y
%bounds - matrix with upper and lower limit of each parameter
%
%output:
%fit_val - same shape as initial_guess
% This is an adapted Ordinary Least Squares cost function
OLS=@(b,x,y,f,bounds) sum((f(b,x) - y).^2) + ... % OLS part
inf^(any(b<bounds(:,1))-1) + ...%converts true to inf
inf^(any(b>bounds(:,2))-1);
% If you don't have bounds for your fitted parameters, set them to inf
bounds=inf*ones(numel(initial_guess),2);
bounds(:,1)=-inf;
% Use fminsearch to minimise the OLS function
opts = optimset('MaxFunEvals',50000, 'MaxIter',10000);
fit_val = fminsearch(OLS, initial_guess(:), opts,x,y,f,bounds);

카테고리

Help CenterFile Exchange에서 Optimization Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by