I defined a function that computes a specific sum and now I want to plot it over x where 0<x<1. I am getting an error saying incompatible sizes and am not sure how to fix it.
f = @(x,y,z) sum(sin((3:15).*sqrt(x*y))+z);
x = linspace(0,1,10);
y = 0.5;
z = 0.1;
plot(x,f(x,y,z))

댓글 수: 1

You have two arrays in the function of different sizes that you are trying to compute together, namely "x" and [3:15]. They need to be the same size for your function to work. How you resolve that depends on your intent.

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2022년 9월 6일
편집: Torsten 2022년 9월 6일
f = @(x,y,z) sum(sin((3:15).*sqrt(x*y))+z);
x = linspace(0,1,100);
y = 0.5;
z = 0.1;
plot(x,arrayfun(@(x)f(x,y,z),x))
But is it really correct to have the constant value z within the sum ?

댓글 수: 1

I guess it doesnt need to be it was just part of the question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2022년 9월 6일

댓글:

2022년 9월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by