Using lsqcurvefit during conditions

Hi
I have a data which I must to fit it with :
I have an Excel file:
My code is :
clc
clear all
Data=load('1.csv');
t=Data(:,1);
x_data=Data(:,2);
y=Data(:,3);
fun=@(x,x_data)x*sqrt(((x_data/x).^2)-1)*sign(x_data);
x0=0.72*10^-6; %initial
A = lsqcurvefit(fun,x0,x_data,y);
But my answer is imaginary every time...
What is wrong?!

3 件のコメント

Walter Roberson
Walter Roberson 2020 年 9 月 17 日
Your fun() is not taking into account the abs(x_data/x) > 1 part
But since x_data is a vector of values, it is not clear which x_data to be using for abs(x_data/x) > 1 ?
The value I find is about 5E-9 with any value below that not making any notable change, until you get down to sqrt(realmin) at which point you get numeric problems.
Pouyan Missaghian
Pouyan Missaghian 2020 年 9 月 17 日
Can I see your code ? I dont know how to tell Matlab that there is a condition abs(x_data/x) > 1 ....
Walter Roberson
Walter Roberson 2020 年 9 月 17 日
Data=load('1.csv');
x_data=Data(:,2);
y=Data(:,3);
fun=@(x,x_data)x.*sqrt(((x_data./x).^2)-1).*sign(x_data).*(abs(x_data./x) > 1);
f_vec = @(x) sum((fun(x,x_data)-y).^2);
x0=0.72*10^-6; %initial
fminunc(f_vec, x0)
ans =
5.423876953125e-07
but then I tested by hand to see if a better result was available, and found that you stopped getting changes about f_vec(5e-9)

サインインしてコメントする。

回答 (1 件)

Pouyan Missaghian
Pouyan Missaghian 2020 年 9 月 17 日

0 投票

Please can anyone help ?!

カテゴリ

タグ

質問済み:

2020 年 9 月 16 日

コメント済み:

2020 年 9 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by