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 ....
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 ?!

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

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