What code would you input to represent the equation for the volume of a sphere without getting an undefined variable error?

조회 수: 3 (최근 30일)
V=(4*pi*r^3)/3

채택된 답변

John D'Errico
John D'Errico 2016년 6월 19일
편집: John D'Errico 2016년 6월 19일
Easy, peasy.
V=(4*pi*r.^3)/3;
I added a semi-colon at the end, and I used .^ for the exponent, in case r is an array or vector.
Since you apparently are getting an undefined variable error, then you need to tell us more.
My guess is, you actually want to create a function of the radius, so that r is indeed undefined at the time you create the function.
V= @(r ) (4*pi*r.^3)/3;
Or possibly, you want to create this in symbolic form. In that case, you need to define r as symbolic.
help syms
How can we know what is in your mind?
  댓글 수: 4
Ethan Sehrt
Ethan Sehrt 2016년 6월 19일
yeah I don't have the symbolic toolbox and whenever I type help syms, it corrects it to help sum. I suppose this is a result of not having the symbolic toolbox. So I guess volume as a function of the radius is the next best approach.
John D'Errico
John D'Errico 2016년 6월 19일
Yes, you must not have that TB. Within limits, you COULD use my sympoly toolbox. It is on the File Exchange. It is admittedly limited though.

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

추가 답변 (2개)

Tarence Glasker
Tarence Glasker 2017년 9월 22일
tan(x/2) = sort(1-cos(x) / 1+cos(x) how to input matlab

Tarence Glasker
Tarence Glasker 2017년 9월 22일
how to input equation into matlab function tan(x/2) = sort(1-cos(x) / 1+cos(x);?

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by