Function, dot, help me for solution
Ältere Kommentare anzeigen
% I couldnt find my mistake
v=19*10^-3;
N=314;
R=25*10^-3;
L=50*10^-3;
C=1*10^-4;
e=0.1:0.1:0.9;
W=@(e) v*N*R*L*(L/C)^2*(e./4).*((16*e.^2+pi^2*(1-e.^2))^0.5/(1-e.^2).^2);
%W depends on e
sm=@(W) v*N*L*R/(4*W.*(L/C)^2);
%sm depends on W
plot(e,sm(W))
5 Kommentare
Adam Danz
am 2 Aug. 2022
I ran your code to produce the error. In the future, you can run your code using the Run Feature (Green triangle button in the tool strip).
Gloria
am 2 Aug. 2022
Adam Danz
am 2 Aug. 2022
The error message tells you the problem.
sm=@(W) v*N*L*R/(4*W.*(L/C)^2);
^ W is a function handle
Perhaps you meant to provide an input to W()?
Walter Roberson
am 2 Aug. 2022
W = @(e) v*N*R*L*(L/C)^2*(e./4).*((16*e.^2+pi^2*(1-e.^2))^0.5./(1-e.^2).^2);
Akzeptierte Antwort
Weitere Antworten (1)
John D'Errico
am 2 Aug. 2022
Bearbeitet: John D'Errico
am 2 Aug. 2022
Your problem has NOTHING to do with dots. This is a common mistake we see made here.
Suppose you have a pair of function handles, and you want to "add" the functions together? For example, suppose we try this:
F1 = @(x) x.^2;
F2 = @(x) x+1;
One might hope that the sum of those two function handles would be just a new function handle. I might try to write it as F3 = F1 + F2. If I did however, MATLAB would throw an error, just as you found. Instead, you need to create a new function handle, by adding the results of each of the two.
F3 = @(x) F1(x) + F2(x);
As you can see, we can use it as we would expect to happen.
F3(5)
Had I just tried to add or multiply the two function handles together, we would an error as you saw:
F1 * F2
As I said, you CANNOT add, multiply, subtract or divide function handles. Arithmetic operations do not apply to function handles. You need to do it as I showed above.
1 Kommentar
Gloria
am 2 Aug. 2022
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
