'lsqcurvefit' Problem/Set-up Question
4 views (last 30 days)
Show older comments
Hey guys. I'm trying to fit a curve (defined by the 501x2 matrix "data", where data(:,1) is the x-coord and data(:,2) is the y-coord) with the following expression:
Sigma1_stretch = (2*L^(3/2)*alpha - mu*(2/L^(1/2) + (2*gamma*(2/L + L^2 - 3))/L^(1/2) + (gamma*(2/L + L^2 - 3)^2)/L^(1/2)))/L^(1/2) - L*((2*alpha)/L^3 - mu*(2*L + 2*L*gamma*(2/L + L^2 - 3) + L*gamma*(2/L + L^2 - 3)^2))
"mu", "gamma", and "alpha" are all symbolic, and elements of the array:
variables = [mu gamma alpha]
Now, I'm trying to find values for mu, gamma, and alpha that fit the curve defined by the points. "L" in the equation is equivalent to x, which is the input for this function. I was to use 'lsqcurvefit' to fit this data (suggested to me by others). I feel like you all are going to be mad at me for asking, but I can't find a decent example to truly explain what's going on with lsqcurvefit. Wouldn't I just set it up as:
answer = lsqcurvefit(Simga1_stretch,[2 2 2],data(:,1),data(:,2))
This gives me the error "If FUN is a MATLAB object, it must have an feval method."
This also happens when I substitute "x" in for "L" in the above equation, and also when I create a 501x1 matrix, where each row is the equation defined at a corresponding x-coordinate. Help?
0 Comments
Answers (1)
Walter Roberson
on 2 Mar 2012
The expression you pass in as the first argument has to evaluate to a numeric value, either by being numeric directly or because it is an object that has a method named "feval".
The expression you are passing is symbolic as it involves symbolic variables. Symbolic expressions are not numeric directly, and do not have a method named "feval".
What might work is:
SSmag = @(mu, gamma, alpha) (2*L^(3/2)*alpha - mu*(2/L^(1/2) + (2*gamma*(2/L + L^2 - 3))/L^(1/2) + (gamma*(2/L + L^2 - 3)^2)/L^(1/2)))/L^(1/2) - L*((2*alpha)/L^3 - mu*(2*L + 2*L*gamma*(2/L + L^2 - 3) + L*gamma*(2/L + L^2 - 3)^2));
Sigma1_stretch = @(X) SSmag(X(1),X(2),X(3);
answer = lsqcurvefit(Simga1_stretch,[2 2 2],data(:,1),data(:,2));
where mu, gamma, and alpha are not declared symbolic.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!