Attached (in the images) are the problem, and what the graph is supposed to look like. Here is my code:
% Given Values
C= 15 *(10^-6);
Vm= 24;
L= 240 * 10^-3;
R=[10:1:40];
f=linspace(60,110,31);
w= 2*pi*f;
% Given functions
Top= Vm;
Bottom=sqrt((R.^2)+(w*L-(1./(w.*C))).^2);
I=[Top./Bottom]'
mesh(w,R,I)
When I run it I get this error:
Error using mesh (line 75)
Z must be a matrix, not a scalar or vector.
Error in ICA_4 (line 12)
mesh(w,R,I)

 채택된 답변

Image Analyst
Image Analyst 2017년 1월 28일
편집: Image Analyst 2017년 1월 28일

0 개 추천

You were very close. You just had an error using mesh() instead of meshgrid as instructed. I corrected that plus a few other small things:
% Initialization / clean-up code.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Given Values
C = 15E-6;
Vm = 24;
L = 240E-3;
R = [10:1:40]
f = linspace(60,110,31);
[f2, R2] = meshgrid(f, R);
w = 2*pi*f;
w2 = 2*pi*f2;
% Compute function surface.
Top = Vm;
Bottom = sqrt(R2.^2 + (w2*L-(1./(w2.*C))).^2);
I = (Top./Bottom)';
% Now plot everything.
surf(R, w, I);
ylabel('omega (angular frequency)', 'FontSize', fontSize);
xlabel('R', 'FontSize', fontSize);
zlabel('I', 'FontSize', fontSize);
ydir ='reverse';
view(gca,[-133.1 34.8]);
grid(gca,'on');

댓글 수: 2

Pape Traore
Pape Traore 2017년 1월 28일
Thank you so much but does mesh grid exactly and what is ydir and gcc
gca is the current axes. ydir just reverses the direction of the y axis. Actually I should have had this, to turn the omega axis around:
ax=gca;
ax.YDir ='reverse';

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

추가 답변 (1개)

Jan
Jan 2017년 1월 27일

0 개 추천

Your w, R and I are vectors with 31 elements. The first input of mesh must be a matrix containing the Z values to the grid of x and y values.
The text of the assignment mentions, that meshgrid should be used.
Notes:
  • 15 *(10^-6) is an expensive power operation, while 15e-6 is a cheap constant. The runtime does not matter when you define one constant, but it is a good programming style to consider this.
  • 10:40 looks easier and is even faster than [10:1:40], see why-not-use-square-brackets.

카테고리

도움말 센터File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

질문:

2017년 1월 27일

댓글:

2017년 1월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by