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
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
2020년 9월 17일
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개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!