I m writing a program to solve equations for some material properties, this is my first attemp:::
%initial attempt of the excel solver function
function solver123
%fixed values
a = 3.17728059841674;
b = -0.004077453872434;
c = -0.001108633782363;
d = -0.000376215283911;
E1 =170;
E2 =10;
E=E1/E2;
v12 =0.335;
alpha1 =5*10^-7;
alpha2 =28*10^-6;
delT =-156;
%Constant C1-C17
C1 = 9*a*b^2*(1+E);
C2 = 9*a^2*b*(1+E);
C3 = 20*a*b^2*v12;
C4 = 20*a^2*b*v12;
C5 = 60*b^2*(E-1);
C6 = 60*a^2*(1-E);
C7 = 120*a*b*(1-E);
C8 = 120*a*b*(E-1);
C9 = 240*b*(delT*(alpha1*E+alpha1*v12+alpha2*v12+alpha2) ...
-d*(1+E) -2*c*v12);
C10 = 240*a*(delT*(alpha1*E+alpha1*v12+alpha2*v12+alpha2) ...
-d*(1+E) -2*c*v12);
C11 = 240*b*(delT*(alpha1*E+alpha1*v12+alpha2*v12+alpha2) ...
-c*(1+E) -2*d*v12);
C12 = 240*a*(delT*(alpha1*E+alpha1*v12+alpha2*v12+alpha2) ...
-c*(1+E) -2*d*v12);
C13 = 960*a*(1+E)+1920*b*v12;
C14 = 960*b*(1+E)+1920*a*v12;
C15 = 2880*(delT*(alpha1*v12-alpha1*E-alpha2*v12+alpha2)+c*(E-1));
C16 = 2880*(delT*(alpha1*E-alpha1*v12+alpha2*v12-alpha2)+d*(1-E));
C17 = a*b*(1+E);
C18 = 2*a*b*v12;
C19 = 12*a*(1-E);
C20 = 12*b*(E-1);
C21 = 48*(delT*(alpha1*E+alpha1*v12+alpha2*v12+alpha2) ...
-c*(1+E)-2*d*v12);
C22 = 48*(delT*(alpha1*E+alpha1*v12+alpha2*v12+alpha2) ...
-d*(1+E)-2*d*v12);
%dW equations
%Lx =x(1), Ly =x(2), H =x(3)
F = @(x) [(C1*x(1)*x(1)+C3*x(2)*x(2)+C5*x(3)+C9)*x(1)*x(1) ...
+(C1*x(2)*x(2)+C7*x(3)+C11)*x(2)*x(2) ...
+(C13*x(3)+C15)*x(3); ...
(C2*x(1)*x(1)+C4*x(2)*x(2)+C8*x(3)+C10)*x(1)*x(1) ...
+(C2*x(2)*x(2)+C6*x(3)+C12)*x(2)*x(2) ...
+(C14*x(3)+C16)*x(3); ...
C17*x(2)*x(2)+C18*x(1)*x(1)+C19*x(3)+C21; ...
C17*x(1)*x(1)+C18*x(2)*x(2)+C20*x(3)+C22];
InitialGuess = [0.25;0.25;0.001];
Options = optimset('Display','iter','TolX',1e-20,'TolFun',1e-20);
XY = fsolve(F, InitialGuess, Options);
format long
%display solutions for E1/E2,al1,al2,v12
XY(1)
XY(2)
XY(3)
%display solutions for the 4 equations (should be zeros)
ShouldBeZero = F(XY)
but this is what I keep getting :::
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> solver123>@(x)[(C1*x(1)*x(1)+C3*x(2)*x(2)+C5*x(3)+C9)*x(1)*x(1),+(C1*x(2)*x(2)+C7*x(3)+C11)*x(2)*x(2),+(C13*x(3)+C15)*x(3);(C2*x(1)*x(1)+C4*x(2)*x(2)+C8*x(3)+C10)*x(1)*x(1),+(C2*x(2)*x(2)+C6*x(3)+C12)*x(2)*x(2),+(C14*x(3)+C16)*x(3);C17*x(2)*x(2)+C18*x(1)*x(1)+C19*x(3)+C21;C17*x(1)*x(1)+C18*x(2)*x(2)+C20*x(3)+C22] at 49
F = @(x) [(C1*x(1)*x(1)+C3*x(2)*x(2)+C5*x(3)+C9)*x(1)*x(1) ...
Error in ==> fsolve at 193
fuser = feval(funfcn{3},x,varargin{:});
Error in ==> solver123 at 61
XY = fsolve(F, InitialGuess, Options);
What does this message mean?
How can the problem be solved?
Many thanks.
Gautam Vallabha - 10 Jul 2008 20:34 GMT
tinafong <yttf20@bath.ac.uk> wrote in message
<16451037.1215099976221.JavaMail.jakarta@nitrogen.mathforum.org>...
> [a lot of setup code snipped away]
>
[quoted text clipped - 11 lines]
> ??? Error using ==> vertcat
> CAT arguments dimensions are not consistent.
The problem is your combination of spacing and line
continuation ("..."). MATLAB treats [1 +2] as a two-element
vector (the "+" is treated as a unary rather than a binary
operator):
-----------------
[1 +2]
% ans =
% 1 2
-----------------
In your code, you have something like this:
[1 ...
+2;
3]
which is equivalent to
[1 +2; 3]
so you get a vertical concatenation error.
To resolve it, move the "+" sign to the end of the previous
lines, like this:
[1+ ...
2;
3]
This forces the "+" to be treated as a binary operator.
By the way, I notice you have a lot of repeated calculations
of x(1)*x(1) and x(2)*x(2). You can simplify this by nesting
the anonymous functions:
-----------------------
% f takes x(1)^2 and x(2)^2 as arguments
f = @(x1s, x2s) x1s + x2s + x1s;
% g precomputes x(1)^2 and x(2)^2 and passes them to f
g = @(x) f(x(1)*x(1), x(2)*x(2));
g([1 2])
% ans =
% 6
Gautam