solve function answer is a 2x1 matrix . how to assign it directly to 2 variables ?
์กฐํ ์: 7 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
v=[2;0;2;1;0;9;3;9;6];
m=max(v);
n=mean(v);
syms x
f=@(x) 2*n-x;
g=@(x) (n/6)*x.^2-2*m;
ezplot(f,[-10,10]);
hold on
ezplot(g,[-10,10]);
grid on
title ('graphs of f(๐ฅ) and g(๐ฅ)')
legend ('f(x)','g(x)');
s=round(solve( 2*n-x == (n/6)*x.^2-2*m ,x),5);
'x1=manually input (1st ans given by solve function above)';
'x2=manually input (2nd ans given by solve function above)';
a=int(2*n-x-(n/6)*x.^2+2*m,x1,x2);
๋๊ธ ์: 2
๋ต๋ณ (1๊ฐ)
John D'Errico
2023๋
11์ 23์ผ
ํธ์ง: John D'Errico
2023๋
11์ 23์ผ
For example, I'll compute the mean of an array, which here will generate a vector of length 2.
A = rand(10,2);
mean(A,1)
Define this function handle:
splitvec = @(x) deal(x(1),x(2));
Now I can use that little toy I just built.
[xm1,xm2] = splitvec(mean(A,1))
It directly takes a vector of length 2, and returns 2 distinct variables. Personally, I will tell you that is a bad idea. That it is better to just return a vector, and index into it.
Of course, this works as well on symbolic results.
syms y
[y1,y2] = splitvec(solve(y^2 - 1 == 0,y))
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Conversion Between Symbolic and Numeric์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!