Effacer les filtres
Effacer les filtres

i want to find k for different values of w using determinants, after that i want to find y2 for the different values but y2 cannot be executed

1 vue (au cours des 30 derniers jours)
%finding k for different values of w
syms k
c44=44;
i=sqrt(-1);
w=1:3;
y1=zeros(1,length(w));
s=sym(zeros(1,length(w)));
p=sym(zeros(1,length(w)));
q=sym(zeros(1,length(w)));
y=sym(zeros(1,length(w)));
for j=1:length(w)
s(j)=c44*exp(k)*w(j);
p(j)=c44/w(j);
q(j)=c44+w(j)*i/k^2;
A=[c44*s(j) 2;p(j) q(j)];
z=det(A);
y(j)=vpasolve(z,k);
disp(y)
y1=real(y);
%relation between y1(or value of k) and w
y2(j)=w/y1(j);
end
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

Error in sym/privsubsasgn (line 1200)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);

Error in indexing (line 1031)
C = privsubsasgn(L,R,inds{:});

Réponse acceptée

Steven Lord
Steven Lord le 9 Nov 2023
w is a vector.
w=1:3
w = 1×3
1 2 3
y1(j) is a scalar. For purposes of this example I'll show a "dummy" y1 vector.
y1 = [4 5 6];
j = 1;
y1(j)
ans = 4
What do you get when you divide w by y1(j)? What size is that result?
result = w/y1(j)
result = 1×3
0.2500 0.5000 0.7500
y2(j) is also a scalar (a 1-by-1 array.)
Can you stuff a 1-by-3 vector into a 1-by-1 array? To use a metaphor, can you fit three eggs into the same cup of an egg carton (without scrambling them)? No, you can't. So MATLAB throws an error when you try.
Perhaps you meant to divide w(j) by y1(j)?

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by